puffnfresh/roy

Ambiguous syntax for functions, constructors

alsonkemp opened this issue · 0 comments

In test/deep_matching.roy:

let xor e = match e
  case (Left (Left n)) = 0
  case (Left (Right n)) = n
  case (Right (Left n)) = n
  case (Right (Right n)) = 0

Is the first "Left" an identifier or a function? Haskell solves this by using UpperCase for constructors and lowerCase for variables:

An identifier consists of a letter followed by zero or more letters, digits, 
underscores, and single quotes. Identifiers are lexically distinguished 
into two namespaces (Section 1.4): those that begin with a 
lowercase letter (variable identifiers) and those that begin with an 
upper-case letter (constructor identifiers). Identifiers are case sensitive: 
name, naMe, and Name are three distinct identifiers (the first 
two are variable identifiers, the last is a constructor identifier).

I'd suggest adopting Haskell's syntax. Updating the example above

let xor e = match e
  case (Left (Left n)) = 0  // constructor
  case (Left (Right n)) = n // constructor
  case (left (Left n)) = 0  // function
  case (left (Right n)) = n  // function
  case (Right (Left n)) = n
  case (Right (Right n)) = 0