[Haskell-cafe] Smart Constructor Puzzle
lrpalmer at gmail.com
Thu Dec 20 23:56:23 EST 2007
On Dec 21, 2007 4:39 AM, Ronald Guida <ronguida at mindspring.com> wrote:
> Finally, I tried to define vecLength, but I am getting an error.
> > vecLength :: (Peano s) => Vec s t -> Int
> > vecLength _ = pToInt (pGetValue :: s)
The s in (pGetValue :: s) is different from the s in (Peano s). Use
the "scoped type variables" extension:
vecLength :: forall s. (Peano s) => Vec s t -> Int
vecLength _ = pToInt (pGetValue :: s)
The forall introduces a scope for s, which type signatures usually do not.
> < Could not deduce (Peano s1) from the context ()
> < arising from a use of `pGetValue'
> < Possible fix:
> < add (Peano s1) to the context of the polymorphic type `forall s. s'
> < In the first argument of `pToInt', namely `(pGetValue :: s)'
> < In the expression: pToInt (pGetValue :: s)
> < In the definition of `vecLength':
> < vecLength _ = pToInt (pGetValue :: s)
> Any suggestions?
> -- Ron
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe