I wrote (to the Haskell Mailing List)

>   newtype Fruit = Int
>   newtype Apples = Apples Fruit
>   newtype Bananas = Bananas Fruit
>
>   noBananas :: Bananas -> Bool
>   noBananas (Bananas bananas)
>       = bananas == 0
>
>   yesWeHaveNoBananas
>       = noBananas (Bananas 0)
>
>   yesWeHaveNoApples
>       = noBananas (Apples 0)

> (Hope this is correct, I don't have a Haskell 1.3 compiler handy)

It isn't. Second try:

   newtype Fruit = Fruit Int
   newtype Apples = Apples Fruit
   newtype Bananas = Bananas Fruit

   noBananas :: Bananas -> Bool
   noBananas (Bananas (Fruit bananas))
        = bananas == 0

   yesWeHaveNoBananas
        = noBananas (Bananas (Fruit 0))

   yesWeHaveNoApples
        = noBananas (Apples (Fruit 0))

Even more constructors!


Cheers,

Ronny Wichers Schreur



Reply via email to