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: Extend instance for List (Graham Gill)
2. Monad and bind operator interpretation (Raja)
3. Re: Monad and bind operator interpretation (D?niel Arat?)
4. Re: Doubts about functional programming paradigm (John Lusk)
5. Re: Monad and bind operator interpretation (Joel Williamson)
6. Re: Monad and bind operator interpretation (Theodore Lief Gannon)
----------------------------------------------------------------------
Message: 1
Date: Mon, 14 Dec 2015 12:43:08 -0500
From: Graham Gill <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Extend instance for List
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8; format=flowed
Thank you Gesh. Your reply is very helpful. I guessed that the correct
Extend instance for List is needed for Comonad, but didn't have any
intuition about it.
The way the NICTA course is structured, there's no mention of the
dependence between "extend" and "copure" (equivalent to extract and
duplicate I suppose) via the Comonad laws when considering Extend first
by itself. I'm not knocking the NICTA course. I've found it useful. A
quick paragraph or two as you've written, stuck into the source files as
comments, would improve it.
Regards,
Graham
On 12/14/2015 5:53 AM, Gesh wrote:
> On December 14, 2015 6:57:27 AM GMT+02:00, Graham Gill
> <[email protected]> wrote:
>> The NICTA course <https://github.com/NICTA/course> includes exercises
>> on
>> the type class Extend, in Course/Extend.hs. Extend is a superclass of
>> Comonad. Here's the class definition:
>>> -- | All instances of the `Extend` type-class must satisfy one law.
>>> This law
>>> -- is not checked by the compiler. This law is given as:
>>> --
>>> -- * The law of associativity
>>> -- `?f g. (f <<=) . (g <<=) ? (<<=) (f . (g <<=))`
>>> class Functor f => Extend f where
>>> -- Pronounced, extend.
>>> (<<=) ::
>>> (f a -> b)
>>> -> f a
>>> -> f b
>>>
>>> infixr 1 <<=
>> Could someone please motivate the Extend instance for List? (Its
>> implementation is left as an exercise. In the course, type List a is
>> isomorphic to [a].) Some of the tests (<<=) is expected to pass are
>> shown, and make clear what ought to happen.
>>> -- | Implement the @Extend@ instance for @List@.
>>> --
>>> -- >>> length <<= ('a' :. 'b' :. 'c' :. Nil)
>>> -- [3,2,1]
>>> --
>>> -- >>> id <<= (1 :. 2 :. 3 :. 4 :. Nil)
>>> -- [[1,2,3,4],[2,3,4],[3,4],[4]]
>>> --
>>> -- >>> reverse <<= ((1 :. 2 :. 3 :. Nil) :. (4 :. 5 :. 6 :. Nil) :.
>> Nil)
>>> -- [[[4,5,6],[1,2,3]],[[4,5,6]]]
>> The following (wrong, according to the tests) Extend instance for List
>> nevertheless obeys the types and obeys the Extend law of associativity.
>>> instance Extend List where
>>> (<<=) ::
>>> (List a -> b)
>>> -> List a
>>> -> List b
>>> (<<=) f = (:. Nil) . f
>> (:. Nil) is analogous to (: []), create a singleton list.
>>
>> I can't find a good reference on the Extend type class to convince me
>> why the correct Extend instance for List in the course is the desirable
>>
>> one. (I'm not saying my version is desirable, in fact it seems fairly
>> useless, but it works.)
>>
>> Graham
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> Indeed, your implementation is a valid Extend instance. However, it cannot be
> extended into a valid Comonad, whereas the supplied instance can.
>
> Can you see why?
> Hint: In order to be a Comonad, an Extend instance must also supply a
> function extract:: f a -> a which must be an identity for extend. Is this
> possible for your instance?
>
> The intuition behind Extend is that given a computation that takes into
> account the context of the values in your container, it applies that
> computation everywhere, passing it the appropriate context. Thus, elements of
> List may be considered as having the remainder of the list as their context,
> and that is indeed what is passed to the computation, as evidence by extend
> id.
>
> Indeed, this function is so essential to the essence of a Comonad that it is
> given its own name - duplicate - and forms the building block for an
> equivalent set of laws for Comonad, namely:
> - duplicate . duplicate = fmap duplicate . duplicate
> - extract . duplicate = id = fmap extract . duplicate
> (If you've heard of join in the context of Monad, this is precisely the dual
> set of laws it satisfies)
>
> Indeed, it may be easier to prove your Extend instance doesn't extend to a
> Comonad instance by using this formulation of the laws.
>
> HTH,
> Gesh
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
Message: 2
Date: Mon, 14 Dec 2015 12:49:12 -0500
From: Raja <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Monad and bind operator interpretation
Message-ID:
<CAPZi6dNOHZRr+3Rn828aagdy09NkPy_WPy2zwbAp=wf6qp6...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
The type signature of bind (>>=) is as follows:
(>>=) :: m a -> (a -> m b) -> m b
One interpretation of this could be as follows:
bind takes two parameters (m a & f) and returns m b (the same type returned
by f)
So extending this interpretation - can I swap the two parameters (?)
Now my new hypothetical interpretation becomes:
(>>=) :: (a -> m b) -> m a -> m b
If i further add parens:
(>>=) (a -> m b) -> (m a -> m b)
This allows me to slightly tweak my interpretation:
bind takes one param f (of type a -> m b) and returns another param f (of
type m a -> m b)
This feels like a more intuitive way to think about Monads - am I on the
right track?
(not that I want to switch the params permanently - just trying to get a
feel for monads)
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20151214/6dea19fa/attachment-0001.html>
------------------------------
Message: 3
Date: Mon, 14 Dec 2015 19:17:23 +0100
From: D?niel Arat? <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Monad and bind operator
interpretation
Message-ID:
<CAHvKd2KzabS26-jvZZ9By+7D6iTCcXq7mzGODTecGgdHG=-j...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
On 14/12/2015, Raja <[email protected]> wrote:
> So extending this interpretation - can I swap the two parameters (?)
>
> Now my new hypothetical interpretation becomes:
>
> (>>=) :: (a -> m b) -> m a -> m b
Sure,
bind' :: Monad m => (a -> m b) -> m a -> m b
bind' = flip (>>=)
> If i further add parens:
>
> (>>=) :: (a -> m b) -> (m a -> m b)
Yeah, that's exactly the same thing. Types are right associative.
------------------------------
Message: 4
Date: Mon, 14 Dec 2015 13:29:36 -0500
From: John Lusk <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Doubts about functional programming
paradigm
Message-ID:
<CAJQkMbYiWqfRiRTh6D+-N01ykCDNmSs7RT4=mrr6uws6cju...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Thanks.
On Mon, Dec 14, 2015 at 12:24 PM, Imants Cekusins <[email protected]> wrote:
> Erlang OTP
>
> http://www.erlang.org/
>
> https://en.m.wikipedia.org/wiki/Open_Telecom_Platform
>
> _______________________________________________
> 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/20151214/9a3d8ac6/attachment-0001.html>
------------------------------
Message: 5
Date: Mon, 14 Dec 2015 18:41:09 +0000
From: Joel Williamson <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Monad and bind operator
interpretation
Message-ID:
<cajgxsepbegdkp7-cy9nnmhpmiq_ycco5wqr0uzvanrx7zef...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
This function is actually in the Prelude as (=<<).
On Mon, 14 Dec 2015, 13:17 D?niel Arat? <[email protected]> wrote:
> On 14/12/2015, Raja <[email protected]> wrote:
> > So extending this interpretation - can I swap the two parameters (?)
> >
> > Now my new hypothetical interpretation becomes:
> >
> > (>>=) :: (a -> m b) -> m a -> m b
>
> Sure,
> bind' :: Monad m => (a -> m b) -> m a -> m b
> bind' = flip (>>=)
>
> > If i further add parens:
> >
> > (>>=) :: (a -> m b) -> (m a -> m b)
>
> Yeah, that's exactly the same thing. Types are right associative.
> _______________________________________________
> 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/20151214/013293a2/attachment-0001.html>
------------------------------
Message: 6
Date: Mon, 14 Dec 2015 14:04:57 -0800
From: Theodore Lief Gannon <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Monad and bind operator
interpretation
Message-ID:
<cajopsuc-vu+12hh+d0q9sbnepagy7bp1y9jhizfkkhw0yzg...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Yeah, after my first couple of significant Haskell projects I came to the
conclusion that having (>>=) instead of (=<<) as the "canonical bind" is a
wart. (>>=) makes for clean desugaring of do notation, but obscures that (a
-> m b) -> (m a -> m b) intuition, which I think is more important
pedagogically and also tends to be cleaner in non-do monadic code.
To a beginner, flip is an easy mechanical concept, but analyzing the
resultant type for new insights is not a habit yet. The one whose purpose
is purely mechanical should be "the flipped one."
On Dec 14, 2015 10:41 AM, "Joel Williamson" <[email protected]>
wrote:
> This function is actually in the Prelude as (=<<).
>
> On Mon, 14 Dec 2015, 13:17 D?niel Arat? <[email protected]> wrote:
>
>> On 14/12/2015, Raja <[email protected]> wrote:
>> > So extending this interpretation - can I swap the two parameters (?)
>> >
>> > Now my new hypothetical interpretation becomes:
>> >
>> > (>>=) :: (a -> m b) -> m a -> m b
>>
>> Sure,
>> bind' :: Monad m => (a -> m b) -> m a -> m b
>> bind' = flip (>>=)
>>
>> > If i further add parens:
>> >
>> > (>>=) :: (a -> m b) -> (m a -> m b)
>>
>> Yeah, that's exactly the same thing. Types are right associative.
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
> _______________________________________________
> 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/20151214/0ce1bf0a/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 90, Issue 28
*****************************************