[Haskell-beginners] mapping over newtypes

Stephen Tetley stephen.tetley at gmail.com
Wed Dec 15 22:59:28 CET 2010


Doesn't mapBanana work if you give it this signature:

mapBanana :: (Something -> Something) -> Banana -> Banana
mapBanana f (Banana b) = Banana (f b)


Possibly you are wanting a polymorphic Banana?

newtype Banana a = Banana a

mapBanana :: (a -> b) -> Banana a -> Banana b
mapBanana f (Banana x) = Banana (f x)



More information about the Beginners mailing list