Haskell函数的参数数 [英] Number of Parameters of a Haskell Function

查看:70
本文介绍了Haskell函数的参数数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用ghc进行编译时,它抱怨函数定义左侧的参数数量不同.

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

我想知道这是否是ghc限制.我试着看看我是否 可以在Haskell 2010中找到有关参数数量的任何信息 报告,但我没有成功.

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.

这是合法的Haskell吗?如果不是,此参数计数在哪里 列出限制?

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

推荐答案

这是不合法的.该限制在 Haskell 2010报告:

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

4.4.3.1函数绑定

[...]

请注意,所有定义函数的子句必须是连续的,并且每个子句中的模式数必须相同.

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

这篇关于Haskell函数的参数数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆