[Haskell-beginners] Further constraining types

Henk-Jan van Tuyl hjgtuyl at chello.nl
Sun Aug 7 11:36:58 CEST 2011


On Sun, 07 Aug 2011 08:08:31 +0200, Antoine Latter <aslatter at gmail.com>  
wrote:
>
> You can use non-standard GHC extensions:
>
> Given a function:
>
> someView :: Natural a -> a
>
> you can pattern match like so:
>
> case myNat of
>   (someView -> 5) -> "It's a five!!!"
>
> This requires {-# LANGUAGE ViewPatterns #-} at the top of your source
> file to enable.

Not using any extension:
   case fromNatural myNat of
     5 -> "It's a five!!!"

The function fromNatural is, of course, imported from the module defining  
Natural.

Regards,
Henk-Jan van Tuyl


-- 
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
--



More information about the Beginners mailing list