[Haskell-beginners] fonction in a typeclass that does not mention the type variable

Peter Jones mlists at pmade.com
Wed Aug 21 19:37:23 CEST 2013


Peter Jones <mlists at pmade.com> writes:
> Your `symbolToConstructor' function is too specific for both cases you
> describe.  You'd need to change the `String' argument to `a' and put it
> back in the type class or write it like this:
>
> symbolToInfixLevel :: (Foo a) => a -> Int
> symbolToInfixLevel s = infixLevel $ (symbolToConstructor s) undefined 

Actually, the problem is with your `symbolToConstructor' function.  It
needs to look like this:

symbolToConstructor :: (Foo a) => String -> a

Then symbolToInfixLevel can be:

symbolToInfixLevel :: String -> Int

-- 
Peter Jones, Founder, Devalot.com
Defending the honor of good code





More information about the Beginners mailing list