[Haskell-beginners] mapping over newtypes
Brent Yorgey
byorgey at seas.upenn.edu
Wed Dec 15 23:21:17 CET 2010
On Wed, Dec 15, 2010 at 10:37:02PM +0100, Tim Baumgartner wrote:
> Hello Haskellers,
>
> I defined
>
> newtype Banana = Banana Something
>
> When I work with it, I sometimes use a function
>
> mapBanana f (Banana b) = Banana (f b)
>
> which is of course discarded by the compiler. Is this usual practice
> or are there any better solutions?
This is the usual practice. Think of it as part of the (small) price
we pay to have nice type inference. You may also be interested in
reading about Conal Elliott's notion of "semantic editor combinators"
[1], of which your 'mapBanana' is an example.
-Brent
[1] http://conal.net/blog/posts/semantic-editor-combinators/
More information about the Beginners
mailing list