在这个Haskell程序中,@@是一个中缀运算符,我只想在函数体内本地定义f.(当然,我的实际程序比这更复杂,并且有充分的理由使用中缀表示法.)
infixl 5 @@
(@@) = undefined
f x = x @@ 5 where x @@ y = (x+1) * (y+1)
main = print (f 7)
Run Code Online (Sandbox Code Playgroud)
然而,除非我也做出全球定义,在此写成(@@) = undefined,GHC抱怨"固定签名@@缺乏附带的约束力".如果没有运算符符号的全局定义,有没有办法绕过这个?
Dan*_*ner 16
只是将修复声明放在where子句中似乎工作正常:
f x = x @@ 5 where
infixl 5 @@
x @@ y = (x+1) * (y+1)
Run Code Online (Sandbox Code Playgroud)