[Haskell-beginners] basic use of Applicative
Imants Cekusins
imantc at gmail.com
Thu Jun 25 19:54:13 UTC 2015
-- (a::Int -> b::Bool)
module ApplicativeAb where
-- 2 arg
add3:: Int -> Bool -> Int
add3 x1 addYes
| addYes = x1 + 3
| otherwise = x1
main::IO()
main = do
print $ maybe2 (Just 3) (Just True)
print $ maybe2 (Just 3) (Just False)
print $ list2 [3] [True]
-- maybe
maybe2::Maybe Int -> Maybe Bool -> Maybe Int
maybe2 mi mb = add3 <$> mi <*> mb
-- list
list2::[Int] -> [Bool] -> [Int]
list2 i b = add3 <$> i <*> b
More information about the Beginners
mailing list