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. Re:  basic use of Applicative (KC)
   2. Re:  basic use of Applicative (Imants Cekusins)
   3. Re:  basic use of Applicative (KC)
   4. Re:  basic use of Applicative (Francesco Ariis)
   5. Re:  basic use of Applicative (Imants Cekusins)
   6. Re:  basic use of Applicative (Imants Cekusins)
   7. Re:  Functor fmap: how to (Imants Cekusins)
   8. Re:  basic use of Applicative (Imants Cekusins)
   9. Re:  Functor fmap: how to (Imants Cekusins)


----------------------------------------------------------------------

Message: 1
Date: Thu, 25 Jun 2015 11:04:18 -0700
From: KC <[email protected]>
To: Haskell Beginners <[email protected]>
Subject: Re: [Haskell-beginners] basic use of Applicative
Message-ID:
        <camlkxymnyitvcyhwqhqh6h1-c5_0m3nl9a+s4ub1cxyv1_i...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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" <[email protected]> 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
> [email protected]
> 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-0001.html>

------------------------------

Message: 2
Date: Thu, 25 Jun 2015 20:30:54 +0200
From: Imants Cekusins <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] basic use of Applicative
Message-ID:
        <cap1qinyxw-tmjs_qjwcjh8jjz5falghssveqrdakurvp7te...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

> Words?
> Sentences?

You see, these are only short snippets on purpose. There are many
books and tutorials which cover Functors & Applicatives at length.

This is my first attempt at Functors & Applicatives.  Hopefully it
gives an idea re: how these may be used. Hopefully these snippets are
valid use examples and do not misguide anyone.

I do not yet understand the concepts enough to try to explain them. My
explanations would most likely confuse or amuse people depending on
their experience.

These are but self sufficient modules which compile & work.


------------------------------

Message: 3
Date: Thu, 25 Jun 2015 11:44:13 -0700
From: KC <[email protected]>
To: Haskell Beginners <[email protected]>
Subject: Re: [Haskell-beginners] basic use of Applicative
Message-ID:
        <CAMLKXykh4pX3bp9gFnpt9Q2=7R2phAnQnJORCZ=p7zu=jlw...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

I'm a part time tutor
even though I don't look Elizabethan :D

Try explaining them to increase your understanding

--
--

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

Casey

On Jun 25, 2015 11:31 AM, "Imants Cekusins" <[email protected]> wrote:

> > Words?
> > Sentences?
>
> You see, these are only short snippets on purpose. There are many
> books and tutorials which cover Functors & Applicatives at length.
>
> This is my first attempt at Functors & Applicatives.  Hopefully it
> gives an idea re: how these may be used. Hopefully these snippets are
> valid use examples and do not misguide anyone.
>
> I do not yet understand the concepts enough to try to explain them. My
> explanations would most likely confuse or amuse people depending on
> their experience.
>
> These are but self sufficient modules which compile & work.
> _______________________________________________
> Beginners mailing list
> [email protected]
> 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/5fb3f22b/attachment-0001.html>

------------------------------

Message: 4
Date: Thu, 25 Jun 2015 20:41:36 +0200
From: Francesco Ariis <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] basic use of Applicative
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Thu, Jun 25, 2015 at 08:30:54PM +0200, Imants Cekusins wrote:
> > Words?
> > Sentences?
> 
> You see, these are only short snippets on purpose. There are many
> books and tutorials which cover Functors & Applicatives at length.
> 
> This is my first attempt at Functors & Applicatives.  Hopefully it
> gives an idea re: how these may be used. Hopefully these snippets are
> valid use examples and do not misguide anyone.

Breadcrumb tutorials [1] have a similar approach; maybe you could
collect yours and list them in a single web page, it would be
easier to navigate.

[1] https://acm.wustl.edu/functional/hs-breads.php


------------------------------

Message: 5
Date: Thu, 25 Jun 2015 21:02:03 +0200
From: Imants Cekusins <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] basic use of Applicative
Message-ID:
        <cap1qinzxwypae-dxeu1pxz2qlevaz4dhtrhmykcfqm+p-j4...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

> Try explaining them to increase your understanding

Functor:
take a polymorphic type e.g. Maybe a
define a functor instance for it (fmap)

now we can write an  (a -> a) function and apply it to the polymorphic type


Applicative:
allows to apply (a -> ... -> a) to the polymorphic type for which
Functor & Applicative instance is defined

?


------------------------------

Message: 6
Date: Thu, 25 Jun 2015 21:05:11 +0200
From: Imants Cekusins <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] basic use of Applicative
Message-ID:
        <cap1qinzhfebjz63rahhbl8ttdtya1s9saeir1wvvd-ms7r6...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

> Breadcrumb tutorials [1] have a similar approach; maybe you could
collect yours and list them in a single web page, it would be
easier to navigate.

> [1] https://acm.wustl.edu/functional/hs-breads.php

Interesting. I did not see it before. Thank you for the link.

If anyone wants to use these snippets - modified or not - they are
free and welcome to do so. Don't blame me though.


------------------------------

Message: 7
Date: Thu, 25 Jun 2015 21:44:29 +0200
From: Imants Cekusins <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Functor fmap: how to
Message-ID:
        <CAP1qinZp4J=+suz70to6ngqk3c6o-gwaz2_tm2bsm46qn86...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

as the author just realized :-P, we can fmap (a -> b), too


module FunctorAb where


-- (a -> b)
overTen:: Int -> Bool
overTen x
   | x > 10 = True
   | otherwise = False


-- maybe
maybe1::Maybe Int -> Maybe Bool
maybe1 mi = overTen <$> mi


--  list
list1::[Int] -> [Bool]
list1 l = overTen <$> l


------------------------------

Message: 8
Date: Thu, 25 Jun 2015 21:54:13 +0200
From: Imants Cekusins <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] basic use of Applicative
Message-ID:
        <cap1qinz70yhdpywhv33_mdoa8vo8ks8ewatrkxu3bygcnfk...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

-- (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


------------------------------

Message: 9
Date: Fri, 26 Jun 2015 13:16:02 +0200
From: Imants Cekusins <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Functor fmap: how to
Message-ID:
        <CAP1qinagWfN=e20hdmtrkahh57m6zisr_5k6dfvhm0_udty...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

a Functor instance is defined for IO, so we can fmap (a -> b) over IO, too.
not using IO monad it seems ;)


module FunctorIO where

{-
   usage:
   *FunctorIO> main
   {type something, <enter>}
-}

process:: String -> String
process s = s ++ " .. ok"

main::IO String
main = func getLine


func::IO String -> IO String
func ios = process <$> ios


------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 84, Issue 44
*****************************************

Reply via email to