开发者

What characters are allowed in Haskell function names?

What is a valid name for a function?

Examples

-- works
let µ x = x * x  
let ö x = x * x

-- doesn't work  
let € x = x * x  
let § x = x * x

I am not sure, but my hunch is that Haskell doesn't allow Unicode function names, does it? (Unicode like in http://www.cse.chalmers.se/开发者_Go百科~nad/listings/lib-0.4/Data.List.html)


From the Haskell report:

Haskell uses the Unicode character set. However, source programs are currently biased toward the ASCII character set used in earlier versions of Haskell .

Recent versions of GHC seem to be fine with unicode (at least in the form of UTF-8):

Prelude> let пять=5; два=2; умножить=(*); на=id in пять `умножить` на два
10

(In case you wonder, «пять `умножить` на два» means «five `multiplied` by two» in Russian.)

Your examples do not work because those character are «symbols» and can be used in infix operators but not in function names. See "uniSymbol" category in the report.

Prelude> let x € y = x * y in 2 € 5
10
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜