Andriy Drozdyuk
Andriy Drozdyuk

Reputation: 61091

Can you start function definition with a typeclass?

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

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

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

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

I get an error:

parse error on input `=>'

Who is wrong here?

Upvotes: 7

Views: 135

Answers (1)

Daniel Fischer
Daniel Fischer

Reputation: 183918

The tutorial is wrong, the type class has to come after the ::, the type signature ought to be length :: Num b => [a] -> b.

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

Upvotes: 12

Related Questions