Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Ads the first two elements of a list together
- myFunc :: [Int] -> Int
- myFunc xs = (head xs) + (head $ tail xs)
- myFunc
- |
- (+)
- /
- /
- head head
- |
- tail
- /
- xs
- myFunc2 :: [Int] -> Int
- myFunc2 xs = hxs + (hxs `seq` (head $ tail xs))
- where hxs = head xs
- main :: IO ()
- main = putStrLn "Hello, " >> putStrLn "world"
- biggerThanTen :: Int -> Bool
- biggerThanTen n = n > 10
- example :: String
- example = filter biggerThanTen [1..15] >> return 'a' -- This evaluates to "aaaaa"
- example2 :: [Int]
- example2 =
- [1,2,3] >>=
- (x -> [10,100,1000] >>=
- (y -> return (x * y))) -- ==> [10,100,1000,20,200,2000,30,300,3000]
- main :: IO ()
- main = do
- putStrLn "Hello, "
- putStrLn "World"
- biggerThanTen :: Int -> Bool
- biggerThanTen n = n > 10
- example :: String -- String is a synonym for [Char], by the way
- example = do
- filter biggerThanTen [1..15]
- return 'a'
- example2 :: [Int]
- example2 = do
- x <- [1,2,3]
- y <- [10,100,1000]
- return (x * y)
- do --
- m -- m >> n
- n --
- do --
- x <- m -- m >>= (x ->
- ... -- ...)
- instance Monad [] where
- return x = [x]
- xs >>= f = concatMap f xs
- example2 :: [Int]
- example2 =
- [1,2,3] >>=
- (x -> [10,100,1000] >>=
- (y -> return (x * y)))
- example2 =
- concatMap
- (x -> [10,100,1000] >>=
- (y -> return (x * y)))
- [1,2,3]
- example2 =
- concatMap
- (x -> concatMap
- (y -> return (x * y))
- [10,100,1000])
- [1,2,3]
- example2 =
- concatMap
- (x -> concatMap
- (y -> [x * y])
- [10,100,1000])
- [1,2,3]
- case f x of
- result1 -> case g y of
- result2 -> ....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement