[PL-sem-jr] Monad exercises

Artem Pelenitsyn a.pelenitsyn at gmail.com
Mon Nov 26 23:37:16 EST 2018


Hi,

Attached is the hack I mentioned in the beginning of today's meeting, to
have do-notation without instantiating Functor/Applicative/Monad. It has
its own overhead, though.

DISCLAIMER: Should be of interest to those feeling comfortable with the
monads. It also spoils the solution to the 3rd part of Hugo's assignment.

--
Best, Artem

On Sat, 24 Nov 2018 at 00:12 Hugo Musso Gualandi <hgualandi at inf.puc-rio.br>
wrote:

> Based on feedback from people who already tried the exercises, here are
> some tips:
>
> - The second problem (error handling) is easier than the first one
> (counting operations). I'd do them in that order.
>
> - The do-notation exercises really are a bit awkward because of the
> applicative and functor stuff. They are probably not worth the hassle
> unless you already know Haskell very well.
>
> - As is usually the case with Haskell, it is often easier to think in
> terms of types when writing the code. If it the typechecker accepts it,
> it is probably correct.
>
> - If you are getting stuck because of the Haskell syntax, feel free to
> use a different language instead. The only Haskell features the first
> two exercises need are alebraic data types and first class functions.
> (Type classes are only needed for do-notation)
>
> Have fun!
>
> -- Hugo
>
> On Wed, 2018-11-21 at 21:27 -0500, Artem Pelenitsyn wrote:
> > Hi, here is the three files loaded into online IDE. Click FORK in the
> > upper left corner to start editing your version.
> >
> > 1) m01_direct.hs https://ideone.com/lyQPo8
> > 2) m02_monadic.hs https://ideone.com/iw3CWI
> > 3) m03_donotation.hs https://ideone.com/NDUwy6
> >
> > (I only had to rename modules to Main and add main function to make
> > online thing happy)
> >
> > -- Best, Artem
> >
> > On Wed, 21 Nov 2018 at 18:31 Hugo Musso Gualandi <
> > hgualandi at inf.puc-rio.br> wrote:
> > > Hi everyone,
> > >
> > > I prepared two exercises for playing with Monads, highlighting the
> > > State and the Maybe monads. I lifted them from the Wadler paper
> > > that
> > > we floated around earlier.
> > >
> > > The files can be downloaded from my website (my previous attempt to
> > > attach them to this email hit a paranoid the antivirus filter):
> > >
> http://www.inf.puc-rio.br/~hgualandi/stuff/pljr-monad-problems.tar.gz
> > >
> > > The task for the exercizes is to fill in the "undefined" blanks in
> > > the
> > > example files I provided and to get the code to work. There are
> > > three
> > > files:
> > >
> > > m01_direct: Try to implement the functions with straightforward
> > > Haskell
> > > code.
> > >
> > > m02_monadic: This time, implement the monadic "bind" and "return"
> > > functions and reimplement the evaluators using them.
> > >
> > > m03_donotation: This one adds the necessary boilerplate to the code
> > > from the previous exercise, so it can be hooked up with the actual
> > > Monad typeclass and so you can use do-notation with it. I found
> > > that it
> > > got a bit clunky, so I consider it "extra credit".
> > >
> > > I tried to keep these short but please let me know if you need
> > > anything
> > > else.
> > >
> > > -- Hugo
> > >
> > >
> > > _______________________________________________
> > > Pl-sem-jr mailing list
> > > Pl-sem-jr at lists.ccs.neu.edu
> > > https://lists.ccs.neu.edu/bin/listinfo/pl-sem-jr
>
>
> _______________________________________________
> Pl-sem-jr mailing list
> Pl-sem-jr at lists.ccs.neu.edu
> https://lists.ccs.neu.edu/bin/listinfo/pl-sem-jr
>
-------------- next part --------------
HTML attachment scrubbed and removed
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 03_donotation_rebsyn.hs
Type: text/x-haskell
Size: 2584 bytes
Desc: not available
URL: <http://lists.ccs.neu.edu/pipermail/pl-sem-jr/attachments/20181126/fcf8d472/attachment.hs>


More information about the Pl-sem-jr mailing list