Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. basic use of Applicative (Imants Cekusins)
----------------------------------------------------------------------
Message: 1
Date: Thu, 25 Jun 2015 12:48:51 +0200
From: Imants Cekusins <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] basic use of Applicative
Message-ID:
<CAP1qinYXuhKGXvJ0+OMA1Zo8eu2FAuqa7ewXHp=i3bZ=szx...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
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
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 84, Issue 43
*****************************************