[Haskell-beginners] Extend instance for List
Gesh
gesh at gesh.uni.cx
Wed Dec 16 07:57:21 UTC 2015
On December 15, 2015 12:36:58 PM GMT+02:00, Kim-Ee Yeoh <ky3 at atamo.com> wrote:
>On Tue, Dec 15, 2015 at 12:43 AM, Graham Gill <math.simplex at gmail.com>
>wrote:
>
>I guessed that the correct Extend instance for List is needed for
>Comonad,
>> but didn't have any intuition about it.
>>
>
>List is not comonadic. In this case, the function copure must be of
>type
>[a] -> a, which must necessarily be partial.
>
>(Non-empty lists, on the other hand, are comonadic.)
In fact, it seems this distinction is true of any type that has an empty case, i.e. f s.t. exists g. f a = 1 + g a.
What blinded me was the fact that for such types, usually the definition of extend extends naturally to the empty case. So obviously the possibly-empty types have an Extend instance inherited from their nonempty counterparts, but it is only the latter who have Comonad instances.
>Graham's "Extend" -- I'll explain the scare quotes in a minute --
>instance
>for List obeys the associative law. So it's a valid instance but a bit
>boring. The exercise asks for an interesting instance.
Indeed, the same problem exists dually for Monad, where one can force the empty case always and obtain a Monad isomorphic to Const ().
Thanks for the correction and illumination,
Gesh
>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.
>>
>
>It's a bit terse, but you can find "class Extend f => Comonad f" in
>Comonad.hs. After all, we're only looking at the exercises. The live
>lecture version probably does talk about the dependence.
>
>
>> 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.
>>
>
>Most folks are neutral about the course. If parts of it work for you,
>great. If not, no worries. The whole comonadic business is a bit
>obscure
>and some of the strongest haskell programmers don't bat an eyelid over
>not
>knowing it.
>
>p.s. "Extend" doesn't agree with the CT literature. See the paragraph
>that
>starts "The dual problem is the problem of lifting a morphism" here:
>
>http://ncatlab.org/nlab/show/extension
>
>But calling it a "lift" or "lifting" will only add to the confusion
>since
>monad transformers got first dibs on the terminology. Which is why you
>sometimes see "coextend" or (for the flipped version) "cobind".
>
>
>-- Kim-Ee
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Beginners mailing list
>Beginners at haskell.org
>http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
More information about the Beginners
mailing list