Can you start defining a function with typeclass?

In this tutorial , at the very bottom, the author provides a type of function:

(Num b) => length :: [a] -> b 

So you can see that it starts with typeclass "Num b" (at least that's what I think). But when I try to define something like:

 (Integral a) => lucky :: a -> String 

I get an error message:

Parse error on input `=> '

Who is wrong here?

+7
source share
1 answer

The tutorial is wrong, the type class should appear after :: , the type signature should be length :: Num b => [a] -> b .

The syntax is specified in the language report, section 10.5 context-free syntax , relevant production is gendecl.

+12
source

All Articles