Send Beginners mailing list submissions to beginners@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-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@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: Trouble understanding the type of sequence [Just, Just] (Mihai Maruseac) 2. Re: Trouble understanding the type of sequence [Just, Just] (Chas Leichner) 3. Re: Trouble understanding the type of sequence [Just, Just] (Imants Cekusins) ---------------------------------------------------------------------- Message: 1 Date: Sat, 12 Dec 2015 15:36:18 -0500 From: Mihai Maruseac <mihai.marus...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Trouble understanding the type of sequence [Just, Just] Message-ID: <caomsum+uufgp4ywutfu6qkkw7v34nxs+htavfo6hf85rhip...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 Hi, Maybe is a type and Just is one of it's constructors (the other being Nothing): > data Maybe a = Just a | Nothing On Sat, Dec 12, 2015 at 3:29 PM, Lim H. <limda...@gmail.com> wrote: > Hi everyone, > > Sorry if this email disturbs you. I haven't used a developer's mailing list > before so I'm not sure if I'm violating any etiquette. If I do, please > excuse me. > > I'm trying to understand the type of sequence [Just, Just]. I can understand > sequence [Just 1, Just 2] :: Num a => Maybe [a] > > because when looking at the type of sequence > > sequence :: (Monad m, Traversable t) => t (m a) -> m (t a) > > it is clear that this function takes a collection of monadic values and > return a single monadic value of the collection. Thus, when we call sequence > [Just 1, Just 2] we should get back a Just of [1,2]. Following that train of > thoughts, shouldn't sequence [Just, Just] return a single Just? > > Here is the corresponding SO question > > http://stackoverflow.com/questions/34244574/trouble-understanding-the-type-of-sequence-just-just > > Lim > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Mihai Maruseac (MM) "If you can't solve a problem, then there's an easier problem you can solve: find it." -- George Polya ------------------------------ Message: 2 Date: Sat, 12 Dec 2015 12:43:25 -0800 From: Chas Leichner <c...@chas.io> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Trouble understanding the type of sequence [Just, Just] Message-ID: <CALPPNrzp93RgpHq79CG9Mr345jR23koYfy=ejlydftv58fn...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" The type of just is (a -> Maybe a) so your list has type [a -> Maybe a] which means the Monad instance that sequence is using isn't Maybe, it's (a ->), the type constructor for function types with its first parameter partially applied. This means that the type of sequence specialized to this context uses [] for t, the Traversable and (a ->) for m, the Monad. That is to say sequence :: [a -> Maybe a] -> (a -> [Maybe a]). (a ->) is one way of representing the Reader monad so you can treat its a parameter as a context that computations can run inside. That means that sequence [Just, Just] takes two functions that construct a Maybe value from the value in the context and turns it into a function which constructs a list of Maybe values each one fed from the same context. That is to say that (sequence [Just, Just] $ 4) == [Just 4, Just 4]. On Saturday, December 12, 2015, Lim H. <limda...@gmail.com> wrote: > Hi everyone, > > Sorry if this email disturbs you. I haven't used a developer's mailing > list before so I'm not sure if I'm violating any etiquette. If I do, please > excuse me. > > I'm trying to understand the type of sequence [Just, Just]. I can > understand > sequence [Just 1, Just 2] :: Num a => Maybe [a] > > because when looking at the type of sequence > > sequence :: (Monad m, Traversable t) => t (m a) -> m (t a) > > it is clear that this function takes a collection of monadic values and > return a single monadic value of the collection. Thus, when we call sequence > [Just 1, Just 2] we should get back a Just of [1,2]. Following that train > of thoughts, shouldn't sequence [Just, Just] return a single Just? > Here is the corresponding SO question > > > http://stackoverflow.com/questions/34244574/trouble-understanding-the-type-of-sequence-just-just > > Lim > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151212/8ee49411/attachment-0001.html> ------------------------------ Message: 3 Date: Sat, 12 Dec 2015 22:07:18 +0100 From: Imants Cekusins <ima...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Trouble understanding the type of sequence [Just, Just] Message-ID: <cap1qinzp1ugcvugak0ixphdwcffbn83g4vrdiodj0orln97...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" > when we call sequence [Just 1, Just 2] we should get back a Just of [1,2]. Following that train of thoughts, shouldn't sequence [Just, Just] return a single Just? What would sequence [Just 1, Nothing] return in this case? Just 1 and Nothing are of the same type - they must be: they are part of the same list. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151212/db3bf3f9/attachment-0001.html> ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 90, Issue 24 *****************************************