Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you start function definition with a typeclass?

Tags:

haskell

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?

like image 274
Andriy Drozdyuk Avatar asked Nov 24 '11 20:11

Andriy Drozdyuk


1 Answers

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.

like image 125
Daniel Fischer Avatar answered Oct 24 '22 03:10

Daniel Fischer