Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number of Parameters of a Haskell Function

Tags:

haskell

When I try to compile this with ghc it complains the number of parameters in the left hand sides of the function definition are different.

module Example where

import Data.Maybe

from_maybe :: a -> Maybe a -> a
from_maybe a Nothing = a
from_maybe _ = Data.Maybe.fromJust

I'm wondering whether this is a ghc restriction. I tried to see if I could find anything about the number of parameters in the Haskell 2010 Report but I wasn't successful.

Is this legal Haskell or isn't it? If not, where is this parameter count restriction listed?

like image 565
Marc van Dongen Avatar asked Nov 01 '17 16:11

Marc van Dongen


1 Answers

It's not legal. The restriction is described in the Haskell 2010 Report:

4.4.3.1 Function bindings

[...]

Note that all clauses defining a function must be contiguous, and the number of patterns in each clause must be the same.

like image 119
melpomene Avatar answered Oct 13 '22 00:10

melpomene