[Haskell-cafe] bounded ranges

Chad Scherrer chad.scherrer at gmail.com
Thu Jul 22 18:21:49 EDT 2010

Hello cafe,

I'm trying to do some things with bounded indices so I can carry
around arrays (well, Vectors, really) without needing to refer to the

For example, if I know my indices are Bool values, I can do

> rangeSize (minBound, maxBound :: Bool)

I'd like to be able to do this in general, but...
> :t rangeSize (minBound, maxBound)
    Ambiguous type variable `a' in the constraints:
      `Bounded a'
        arising from a use of `minBound' at <interactive>:1:11-18
      `Ix a' arising from a use of `rangeSize' at <interactive>:1:0-29
    Probable fix: add a type signature that fixes these type variable(s)

I thought it might help to put it into a module and do a better job
with the type, like this:

bdRangeSize :: (Ix i, Bounded i) => i -> Int
bdRangeSize _ = rangeSize (minBound, maxBound :: i)

but I still have problems:

    Could not deduce (Bounded i1) from the context ()
      arising from a use of `maxBound' at MyArray.hs:22:36-43
    Possible fix:
      add (Bounded i1) to the context of an expression type signature
    In the expression: maxBound :: i
    In the first argument of `rangeSize', namely
        `(minBound, maxBound :: i)'
    In the expression: rangeSize (minBound, maxBound :: i)

I thought maybe it's an existential types problem or something, but I
don't understand why it would be coming up here. Any thoughts?

Oh yes, and I'm using  GHC version 6.12.1.


More information about the Haskell-Cafe mailing list