[Haskell-beginners] Bound library questions (David McBride)

Anthony Lee anthonynlee at gmail.com
Sat Aug 18 15:11:20 UTC 2018


Now I understand it.
Thanks a lot!

Anthony

On Sat, Aug 18, 2018 at 5:34 AM <beginners-request at haskell.org> wrote:

> Send Beginners mailing list submissions to
>         beginners at haskell.org
>
> 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
>         beginners-request at haskell.org
>
> You can reach the person managing the list at
>         beginners-owner at haskell.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Beginners digest..."
>
>
> Today's Topics:
>
>    1. Re:  Beginners Digest, Vol 122, Issue 6 (Anthony Lee)
>    2. Re:  Bound library questions (David McBride)
>    3.  Empty list and null (trent shipley)
>    4. Re:  Empty list and null (Ut Primum)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Fri, 17 Aug 2018 09:21:47 -0400
> From: Anthony Lee <anthonynlee at gmail.com>
> To: beginners at haskell.org
> Subject: Re: [Haskell-beginners] Beginners Digest, Vol 122, Issue 6
> Message-ID:
>         <CA+pBo5FSLqbgC=
> L9bONcCb0y+UPSGq6jpVgq60ouKUNk4xNv3w at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> The source code is here: https://github.com/ekmett/bound/
>
> On Fri, Aug 17, 2018 at 8:41 AM <beginners-request at haskell.org> wrote:
>
> > Send Beginners mailing list submissions to
> >         beginners at haskell.org
> >
> > 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
> >         beginners-request at haskell.org
> >
> > You can reach the person managing the list at
> >         beginners-owner at haskell.org
> >
> > When replying, please edit your Subject line so it is more specific
> > than "Re: Contents of Beginners digest..."
> >
> >
> > Today's Topics:
> >
> >    1.  Bound library questions (Anthony Lee)
> >
> >
> > ----------------------------------------------------------------------
> >
> > Message: 1
> > Date: Fri, 17 Aug 2018 06:46:52 -0400
> > From: Anthony Lee <anthonynlee at gmail.com>
> > To: beginners at haskell.org
> > Subject: [Haskell-beginners] Bound library questions
> > Message-ID:
> >         <CA+pBo5HVraf_8jbs15bR6QAy1S7=z_u-3KBwT=
> > c3sqkAgc0m5Q at mail.gmail.com>
> > Content-Type: text/plain; charset="utf-8"
> >
> > In Scope.hs there are some functions I feel difficult to understand,
> > Why fmap/foldmap/traverse is applied three times?
> >
> > instance Functor f => Functor (Scope b f) where
> > fmap f (Scope a) = Scope (fmap (fmap (fmap f)) a)
> > {-# INLINE fmap #-}
> >
> > -- | @'toList'@ is provides a list (with duplicates) of the free
> variables
> > instance Foldable f => Foldable (Scope b f) where
> > foldMap f (Scope a) = foldMap (foldMap (foldMap f)) a
> > {-# INLINE foldMap #-}
> >
> > instance Traversable f => Traversable (Scope b f) where
> > traverse f (Scope a) = Scope <$> traverse (traverse (traverse f)) a
> > {-# INLINE traverse #-}
> > -------------- next part --------------
> > An HTML attachment was scrubbed...
> > URL: <
> >
> http://mail.haskell.org/pipermail/beginners/attachments/20180817/429114c8/attachment-0001.html
> > >
> >
> > ------------------------------
> >
> > Subject: Digest Footer
> >
> > _______________________________________________
> > Beginners mailing list
> > Beginners at haskell.org
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >
> >
> > ------------------------------
> >
> > End of Beginners Digest, Vol 122, Issue 6
> > *****************************************
> >
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://mail.haskell.org/pipermail/beginners/attachments/20180817/2112c0e7/attachment-0001.html
> >
>
> ------------------------------
>
> Message: 2
> Date: Fri, 17 Aug 2018 10:23:53 -0400
> From: David McBride <toad3k at gmail.com>
> To: The Haskell-Beginners Mailing List - Discussion of primarily
>         beginner-level topics related to Haskell <beginners at haskell.org>
> Subject: Re: [Haskell-beginners] Bound library questions
> Message-ID:
>         <CAN+Tr40SXsiWUsasn7hQoryCoXD232PSB-P=
> JrmRR5ToPm93jw at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> The code as it currently stands only has two nested fmaps / foldMaps /
> traverses.
>
> The reason he can do that is because Scope is defined as an "f (Var b a)".
> Since Scope is only a functor if f is also functor, that means you can fmap
> over f, regardless of what it is.  But in addition to that Var is also a
> functor.  So you can fmap over f, and then fmap over the Var inside the f,
> which ends up being two nested fmaps.  That same condition exists for
> foldable and traversable.
>
> On Fri, Aug 17, 2018 at 6:46 AM, Anthony Lee <anthonynlee at gmail.com>
> wrote:
>
> > In Scope.hs there are some functions I feel difficult to understand,
> > Why fmap/foldmap/traverse is applied three times?
> >
> > instance Functor f => Functor (Scope b f) where
> > fmap f (Scope a) = Scope (fmap (fmap (fmap f)) a)
> > {-# INLINE fmap #-}
> >
> > -- | @'toList'@ is provides a list (with duplicates) of the free
> variables
> > instance Foldable f => Foldable (Scope b f) where
> > foldMap f (Scope a) = foldMap (foldMap (foldMap f)) a
> > {-# INLINE foldMap #-}
> >
> > instance Traversable f => Traversable (Scope b f) where
> > traverse f (Scope a) = Scope <$> traverse (traverse (traverse f)) a
> > {-# INLINE traverse #-}
> >
> > _______________________________________________
> > 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/20180817/e0fbde97/attachment-0001.html
> >
>
> ------------------------------
>
> Message: 3
> Date: Sat, 18 Aug 2018 02:13:25 -0700
> From: trent shipley <trent.shipley at gmail.com>
> To: Haskell Beginners <beginners at haskell.org>
> Subject: [Haskell-beginners] Empty list and null
> Message-ID:
>         <CAEFLyb+JS2HGitc9HTTe_suhHsesoM5r=JkT+rRmTmQ5xg=
> Q2A at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Why does Haskell so often seem to treat [] as a general null.
>
> For example I know 0 : 1 : [] gives [0, 1].
>
> But shouldn't it produce a type fault in a consistent world?
>
> Int:Int:List isn't properly a list.  It mixes types.
>
> I expect something like:
>
> Let GSN mean general_scalar_null.
>
> 1 : 2 : GSN  -- works
>
> 1 : 2 : []  -- type fault, cannot mix int and empty list in the same list.
>
> And why does [] == [] : []
> instead of [[], []] == [] : []
>
> What sorts of nullity are there in core Haskell?
>
> Trent.
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://mail.haskell.org/pipermail/beginners/attachments/20180818/dd3bff19/attachment-0001.html
> >
>
> ------------------------------
>
> Message: 4
> Date: Sat, 18 Aug 2018 11:34:23 +0200
> From: Ut Primum <utprimum at gmail.com>
> To: The Haskell-Beginners Mailing List - Discussion of primarily
>         beginner-level topics related to Haskell <beginners at haskell.org>
> Subject: Re: [Haskell-beginners] Empty list and null
> Message-ID:
>         <CANjDmKKcY_CEcOXeeAsT8=
> xW0WLe_MF5MJ7sn_+-yF6WBCGVmQ at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> If you consider the type of the operator *(:)* you have:
>
> Prelude> :t (:)
> (:) :: a -> [a] -> [a]
>
> So it takes an element of type a and a list. So if you write 1:[2,3,4] the
> type is correct, because you give an integer 1 and a list of integers
> [2,3,4]. You will obtain the list of integers [1,2,3,4]. Similarly, writing
> 1:[] is correct and gives you [1] as result.
>
> Then, if you write
> 0 : 1 : []
> (as in your example), is the same as
> 0 : (1 : [])
> so it means 0 : [1], which is [0,1]. So, the operator (:) is right
> associative.
>
> If it was left associative, your example would give an error. Indeed
> (0 : 1) : []
> is not correct in Haskell.
>
> Furthermore, your final examples are both false:
>
> Prelude> [] == [] : []
> False
>
> [[], []] == [] : []
> False
>
> The following is True:
> Prelude> [[]] == [] : []
> True
>
> Indeed if you write [] : [] youy mean you want to build a list whose first
> element (head) is [] and whose "tail" (i.e. the rest of the list) is the
> empty list.
> So, if 1:[] is [1], then []:[] is [[]].
>
> Ut
>
> 2018-08-18 11:13 GMT+02:00 trent shipley <trent.shipley at gmail.com>:
>
> > Why does Haskell so often seem to treat [] as a general null.
> >
> > For example I know 0 : 1 : [] gives [0, 1].
> >
> > But shouldn't it produce a type fault in a consistent world?
> >
> > Int:Int:List isn't properly a list.  It mixes types.
> >
> > I expect something like:
> >
> > Let GSN mean general_scalar_null.
> >
> > 1 : 2 : GSN  -- works
> >
> > 1 : 2 : []  -- type fault, cannot mix int and empty list in the same
> list.
> >
> > And why does [] == [] : []
> > instead of [[], []] == [] : []
> >
> > What sorts of nullity are there in core Haskell?
> >
> > Trent.
> >
> >
> > _______________________________________________
> > 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/20180818/0eebd5a6/attachment.html
> >
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
> ------------------------------
>
> End of Beginners Digest, Vol 122, Issue 7
> *****************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20180818/2298993a/attachment.html>


More information about the Beginners mailing list