<commit_before>module Lwch003 where 
-- fun with GHC
-- : retab 
-- : set +s 
--  set expandtab ts=4 ruler number spell linebreak

----------------
-- recursion -- 
----------------
-- a function calling itself.


qsort []     = []
qsort (x:xs) = qsort smaller ++ [x] ++ larger
                          where
                                smaller = [a|a<-xs,a<=x]
                                larger  = [b|b<-xs,b>x]


-- qsort        :: Ord a => [a]->[a]

------------------
-- Lists -- 
------------------
-- no lists of any type 
-- all lists must be same type
-- recursion is how we loop through lists
empty = []
x = [1,2,3] 
y = 0 : x   
z = empty:empty:empty



xa= 1:(2:(3:(4:[])))
xb= 1:2:3:4:[]
xc :: [Int] 
xc = 1:2:3:4:[]
  
-- :t 0:1:2:3:4:empt

str = "I am a list of characters"
str' = 'I':' ':'a':'m':' ':'a':' ':'l':'i':'s':'t':' ':'t':'o':'o':'!':[] 
-- length ['a'..'z']
-- zip  [1..12] "Call me Ishmael"

count x xs      = length [x'|x' <- xs, x == x']
-- count 'a'  "Call me Ishmael"

doubleList [] = []  
doubleList x = (2 * (head x)) ++ (doubleList (tail x))           
<commit_msg>List functions<commit_after>module Lwch003 where 
-- fun with GHC
-- : retab 
-- : set +s 
--  set expandtab ts=4 ruler number spell linebreak

----------------
-- recursion -- 
----------------
-- a function calling itself.


qsort []     = []
qsort (x:xs) = qsort smaller ++ [x] ++ larger
                          where
                                smaller = [a|a<-xs,a<=x]
                                larger  = [b|b<-xs,b>x]


-- qsort        :: Ord a => [a]->[a]

------------------
-- Lists -- 
------------------
-- no lists of any type 
-- all lists must be same type
-- recursion is how we loop through lists
empty = []
x = [1,2,3] 
y = 0 : x   
z = empty:empty:empty



xa= 1:(2:(3:(4:[])))
xb= 1:2:3:4:[]
xc :: [Int] 
xc = 1:2:3:4:[]
  
-- :t 0:1:2:3:4:empt

str = "I am a list of characters"
str' = 'I':' ':'a':'m':' ':'a':' ':'l':'i':'s':'t':' ':'t':'o':'o':'!':[] 
-- length ['a'..'z']
-- zip  [1..12] "Call me Ishmael"

count x xs      = length [x'|x' <- xs, x == x']
-- count 'a'  "Call me Ishmael"

doubleList [] = []  
doubleList x = (2 * (head x)) : (doubleList (tail x))           
---------------------------
-- Guards ---
-- value matching 

myFunNeg   x  
    | x == 0     = 0
    | x >= 1     = 1 
    | x <  1     = (-1)
    | otherwise  = 0

oddGone x =  
    if null x 
    then [] 
    else 
        if (mod(head x) 2) == 0 
        then (head x) : (oddGone (tail x))
        else oddGone (tail x) 


-- evenGone x = 
--     if null x  
--     then [] 
--     else 
--         if (mod(head x) 1) == 0
--         then (head x) : (oddGone (tail x))
--         else oddGone (tail x) 

{'fraction_non_alphanumeric': 0.2601834862385321, 'fraction_numerical': 0.025321100917431193, 'mean_word_length': 1.4252669039145907, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5823333', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1016, 'n_words': 293}