Skip to content

Instantly share code, notes, and snippets.

@Nil-Zil Nil-Zil/set.hs
Created Jan 20, 2018

Embed
What would you like to do?
head1 :: [a] -> a
head1 [] = error "empty List"
head1 (x:xs) = x
head2 :: [a] -> Maybe a
head2 [] = Nothing
head2 (x:xs) = Just x
filter' :: (a -> Bool) -> [a] -> [a]
filter' _ [] = []
filter' f (x:xs) =
if f x
then x : (filter' f xs)
else filter' f xs
duplicate :: [a] -> [a]
duplicate = concat . (map (\x -> [x, x]))
reverse' :: [a] -> [a]
reverse' [] = []
reverse' (xs:x) = [x] ++ (reverse' xs)
-- head1 [102,105,48,21,22,16]
-- head2 [102,105,48,21,22,16]
-- duplicate [102,105,48,21,22,16]
-- duplicate []
-- reverse' []
-- reverse' [102,105,48,21,22,16]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.