Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What characters are allowed in Haskell function names?

Tags:

haskell

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)

like image 983
mrsteve Avatar asked Feb 16 '11 23:02

mrsteve


People also ask

What characters are allowed in C functions?

A valid identifier can have letters (both uppercase and lowercase letters), digits and underscores. The first letter of an identifier should be either a letter or an underscore.

What does -> mean in Haskell?

(->) is often called the "function arrow" or "function type constructor", and while it does have some special syntax, there's not that much special about it. It's essentially an infix type operator. Give it two types, and it gives you the type of functions between those types.


1 Answers

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
like image 151
Roman Cheplyaka Avatar answered Sep 30 '22 23:09

Roman Cheplyaka