[Haskell-beginners] basic use of Applicative

KC kc1956 at gmail.com
Thu Jun 25 18:04:18 UTC 2015


Words?
Sentences?

--
--

Sent from an expensive device which will be obsolete in a few months! :D

Casey

On Jun 25, 2015 3:48 AM, "Imants Cekusins" <imantc at gmail.com> wrote:

> module BasicApplicative where
>
>
> -- 2 arg
> upd2:: Int -> Int -> Int
> upd2 x1 x2 = x1 * x2
>
> -- 3 arg
> upd3:: Int -> Int -> Int -> Int
> upd3 x1 x2 x3 = x1 * x2 + x3
>
>
> -- pure
> pureMaybe::Int -> Maybe Int
> pureMaybe = pure
>
> pureList::Int -> [Int]
> pureList = pure
>
>
> -- maybe
> maybe2::Maybe Int -> Maybe Int -> Maybe Int
> maybe2 mi1 mi2 = upd2 <$> mi1 <*> mi2
>
>
> -- list
> list2::[Int] -> [Int] -> [Int]
> list2 l1 l2 = upd2 <$> l1 <*> l2
>
> -- same result as list2
> list2p::[Int] -> [Int] -> [Int]
> list2p l1 l2 = pure upd2 <*> l1 <*> l2
>
>
> list3::[Int] -> [Int] -> [Int] -> [Int]
> list3 l1 l2 l3 = upd3 <$> l1 <*> l2 <*> l3
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150625/b39abe4c/attachment.html>


More information about the Beginners mailing list