
29 Sep
2008
29 Sep
'08
3:03 p.m.
2008/9/29 Casey Rodarmor
invertRatio r = denominator r % numerator
Ratio is an instance of Fractional, which means : invertRation = recip ou invert f = 1 / f (probably the default definition of recip anyway).
Is there any way to avoid this, while still letting the user benefit from the nice pattern matching syntax that exposing the data constructor allows?
To this more general question : allow the convenience of pattern matching while keeping a datatype abstract, the latest GHC (6.10) bring a new extension called "view pattern", it may not be ideal but it should be pretty useful in this direction. http://hackage.haskell.org/trac/ghc/wiki/ViewPatterns -- Jedaï