[Haskell-beginners] Constructors as functions (was monad transformers)

Isaac Dupree ml at isaac.cedarswampstudios.org
Fri Aug 14 21:10:40 EDT 2009


Michael P Mossey wrote:
> Michael P Mossey wrote:
>> In Martin Grabmuller's tutorial "Monad Transformers Step by Step", 
>> found here
>>
>> http://user.cs.tu-berlin.de/~magr/pub/Transformers.pdf
>>
> 
> Additional question: in this paper he uses a data constructor in an 
> interesting way: back-quoting it to make it an operator. I thought, 
> "Huh, a constructor is a lot like a function?" I did some experiments 
> and found that I can map a constructor over a list and I can compose a 
> constructor with other functions. Cool. So is a constructor a function, 
> in every sense?

Yes.  In expressions, a constructor is a function, no more and no less 
(albeit with some weird capitalization).  Constructors however, can 
*also* be used in pattern-matching, unlike functions.  That's the 
(only?) special thing about them.

-Isaac


More information about the Beginners mailing list