mrsteve
mrsteve

Reputation: 4142

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/~nad/listings/lib-0.4/Data.List.html)

Upvotes: 29

Views: 4439

Answers (1)

Roman Cheplyaka
Roman Cheplyaka

Reputation: 38758

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

Upvotes: 29

Related Questions