Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/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.  Question in "Monads for Functional Programming"
      (Aggelos Mpimpoudis)
   2. Re:  Question in "Monads for Functional   Programming"
      (Daniel Fischer)
   3. Re:  Parser as an instance of the monad class (Paul Higham)
   4. Re:  Parser as an instance of the monad class (Paul Higham)


----------------------------------------------------------------------

Message: 1
Date: Fri, 14 Jan 2011 02:10:39 +0200
From: "Aggelos Mpimpoudis" <[email protected]>
Subject: [Haskell-beginners] Question in "Monads for Functional
        Programming"
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

Hi all, 

 

I am referring to P. Wadler, "Monads for functional programming," Advanced
Functional Programming, pp. 24-52, 1995. I cannot understand in chapter 2.6,
why a*k = k a. 

 

I cannot ask anyone else this time of night (3am here J), thus I posted
here!

 

Best regards!

 

--

Aggelos Mpimpoudis 

Doctoral Researcher, Pervasive Computing [p-comp.di.uoa.gr] 

SDE, Nessos IT S.A. [www.nessos.gr]

(m): +306942075153 

 <http://gr.linkedin.com/in/aggelosmp> Description: Linkedin
<http://www.facebook.com/aggelosmp> Description: Facebook
<http://www.studentguru.gr/blogs/grnemo/> Description: Blog RSS
<http://twitter.com/aggelosmp> Description: Twitter

 

 

 

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110114/be2135f0/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 655 bytes
Desc: not available
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110114/be2135f0/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 258 bytes
Desc: not available
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110114/be2135f0/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 691 bytes
Desc: not available
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110114/be2135f0/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 570 bytes
Desc: not available
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110114/be2135f0/attachment-0007.png>

------------------------------

Message: 2
Date: Fri, 14 Jan 2011 01:47:52 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Question in "Monads for Functional
        Programming"
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="utf-8"

On Friday 14 January 2011 01:10:39, Aggelos Mpimpoudis wrote:
> Hi all,
>
>
>
> I am referring to P. Wadler, "Monads for functional programming,"
> Advanced Functional Programming, pp. 24-52, 1995. I cannot understand in
> chapter 2.6, why a*k = k a.
>

Wadler uses (*) in that paper for what is (>>=) in Haskell (and unit for 
return).
In 2.6, he treats the identity monad (in Haskell, you have to wrap it in a 
newtype, Wadler uses a type synonym).

If partial application of type synonyms were possible in Haskell, the 
identity monad would be

type Id a = a

instance Monad Id where
  -- return :: Monad m => a -> m a
  return x = x
  -- (>>=) :: Monad m => m a -> (a -> m b) -> m b
  m >>= f = f m

For the unwrapped identity monad, you'd have

return :: a -> a {- = Id a -}
(>>=) :: a -> (a -> b) -> b

A function of type a -> (a -> b) -> b can basically only be the flipped 
application (ignoring seq and undefineds).

Actually (with the newtype), it's

newtype Identity a = Identity { runIdentity :: a }

instance Monad Identity where
  return x = Identity x
  -- f :: a -> Identity b
  (Identity x) >>= f = f x

>
>
> I cannot ask anyone else this time of night (3am here J), thus I posted
> here!
>

You can also ask on #haskell, it's always *not* 3 am somewhere ;)

HTH,
Daniel



------------------------------

Message: 3
Date: Thu, 13 Jan 2011 22:06:36 -0800
From: Paul Higham <[email protected]>
Subject: Re: [Haskell-beginners] Parser as an instance of the monad
        class
To: Iustin Pop <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes

I Just looked at it after your suggestion, Maybe I should have looked  
at it before, because it's way better than the Nothing I was using!

Thanx for the tip,

::paul

On Jan 12, 2011, at 12:01 AM, Iustin Pop wrote:

> On Tue, Jan 11, 2011 at 11:39:48PM -0800, Paul Higham wrote:
>> There are a number of ugly things that you can do at this point that
>> are just plain wrong, so I thought that the right thing to do would
>> be to get the Parser type to be manifested as an instance of the
>> Monad class.  Ok, now what?  Since Parser is only a type synonym it
>> cannot be used directly in the following way:
>>
>>   instance Monad Parser where
>>      return v = . . .
>>      p >>= f  = . . .
>>
>> but since Parser is not an algebraic type as it is defined that
>> won't work either.  So how do you do it?  help .
>
> Have you looked at the book's website? He provides the entire
> Parsing.lhs library, and you can see there an example of how to do it.
>
> regards,
> iustin




------------------------------

Message: 4
Date: Thu, 13 Jan 2011 22:29:47 -0800
From: Paul Higham <[email protected]>
Subject: Re: [Haskell-beginners] Parser as an instance of the monad
        class
To: Brent Yorgey <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII; format=flowed

And thanx to you also, this is starting to make some sense

::paul

On Jan 12, 2011, at 5:49 AM, Brent Yorgey wrote:

> On Tue, Jan 11, 2011 at 11:39:48PM -0800, Paul Higham wrote:
>> I am working my way through Graham Hutton's book and find that his
>> approach to introducing monads is rather nice.  Trouble is that the
>> code there does not work "out of the book".  Specifically, if you
>> define the Parser type as follows:
>>
>>   type Parser a :: String -> [(a,String)]
>>
>> you can then define the return and bind functions as
>>
>>   return v  =  \x -> [(v,x)]
>>   p >>= f   =  \x -> case p x of
>>                        [] -> []
>>                        [(v,y)] -> (f v) y
>>
>> but you get name conflicts with the functions of the same names in
>> the Prelude.  Fair enough.
>>
>> There are a number of ugly things that you can do at this point that
>> are just plain wrong, so I thought that the right thing to do would
>> be to get the Parser type to be manifested as an instance of the
>> Monad class.  Ok, now what?  Since Parser is only a type synonym it
>> cannot be used directly in the following way:
>>
>>   instance Monad Parser where
>>      return v = . . .
>>      p >>= f  = . . .
>>
>> but since Parser is not an algebraic type as it is defined that won't
>> work either.  So how do you do it?  help .
>
> Make Parser a newtype, like so:
>
>  newtype Parser a = Parser (String -> [(a, String)])
>
> Now you will have some extra Parser constructors to deal with, but you
> can make this an instance of Monad just fine.
>
> -Brent
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners




------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 31, Issue 12
*****************************************

Reply via email to