An alternative to the `asTypeOf` idiom, which is also Haskell 98, is to use a newtype instead of a dummy argument:

    newtype RangeSize i = RangeSize { getRangeSize :: Int }

    boundedRangeSize :: Ix i => (i,i) -> RangeSize i
    boundedRangeSize = RangeSize . rangeSize

    bdRangeSize :: (Ix i, Bounded i) => RangeSize i
    bdRangeSize = boundedRangeSize (minBound, maxBound)

Now you can call

    ghci> getRangeSize (bdRangeSize :: RangeSize Bool)
    2

without language extensions and avoid the extra applications due to the dummy argument and the `asTypeOf` call.

Sebastian


--
Underestimating the novelty of the future is a time-honored tradition.
(D.G.)



_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to