Ticket #1102 (new feature request)

Opened 5 years ago

Last modified 9 months ago

Lambda unicode character lex

Reported by: humasect Owned by:
Priority: normal Milestone: _|_
Component: Compiler (Parser) Version: 6.6
Keywords: lambda unicode lexical parse ? Cc: pumpkingod@…, anton.nik@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Easy (less than 1 hour)
Test Case: Blocked By:
Blocking: Related Tickets:

Description

abd ∷ Num a ⇒ a → a abd a = a

(⋴) a b = a ++ b test2 x = map (λx → x ⋴ "abc") -- line 17

Test.hs:17:18: parse error on input `?'


All of these special characters are unicode, and work great, except the lambda. Any unicode character put here gives this error.  http://hackage.haskell.org/trac/haskell-prime/wiki/UnicodeInHaskellSource -- claims otherwise.

Change History

follow-up: ↓ 5   Changed 5 years ago by simonmar

  • priority changed from high to normal
  • status changed from new to closed
  • resolution set to wontfix

I removed the claim on the Haskell-prime wiki, and also removed the failed attempt to support unicode lambda from GHC.

Further discussion is needed here: since λ is a lower-case letter, λx is an identifier. If we want to treat this as meaning \x, that means λ would need to be treated as a "special" character (like parentheses for example). No other alphanumeric character has this property, currently.

  Changed 5 years ago by humasect

  • os changed from MacOS X to Multiple

This sounds like a simple enough strategy, to make it a special case. With or without an option to turn it on/off. There is another similar character, ⋋, which is "left semidirect product" of mathematical symbols. Or ⋀ for "n-ary logical and". Sorry I don't have the unicode ID. So the error message from GHC is real and would have made sense if it were seen under a Unicode terminal. I wonder, some way to use lower case lambda letter as an identifier, aliased to actual lambda syntax? Thanks!

  Changed 3 years ago by simonmar

  • architecture changed from Unknown to Unknown/Multiple

  Changed 3 years ago by simonmar

  • os changed from Multiple to Unknown/Multiple

in reply to: ↑ 1   Changed 2 years ago by pumpkin

  • status changed from closed to reopened
  • resolution wontfix deleted
  • severity changed from major to minor

Replying to simonmar:

I removed the claim on the Haskell-prime wiki, and also removed the failed attempt to support unicode lambda from GHC. Further discussion is needed here: since λ is a lower-case letter, λx is an identifier. If we want to treat this as meaning \x, that means λ would need to be treated as a "special" character (like parentheses for example). No other alphanumeric character has this property, currently.

I'm reasonably sure this could be done unambiguously for the regular greek lambda, but it would add some complexity to the parse. As a simple alternative, we could use some of the new unicode characters from the "Math Alphanumeric Symbols" table (non-BMP). The following characters seem like valid candidates for really easy lexing (unfortunately almost no fonts actually provide glyphs for them, but in principle at least, it should be correct:

𝛌 (1D6CC, MATHEMATICAL BOLD SMALL LAMBDA) 𝜆 (1D706, MATHEMATICAL ITALIC SMALL LAMBDA) 𝝀 (1D740, MATHEMATICAL BOLD ITALIC SMALL LAMBDA) 𝝺 (1D77A, MATHEMATICAL SANS-SERIF BOLD SMALL LAMBDA) 𝞴 (1D7B0, MATHEMATICAL SANS-SERIF BOLD ITALIC SMALL LAMBDA)

What do people think? Would making all these characters lex to behave like a \ be correct behavior? It would still be nice to get the regular BMP greek lambda to have special behavior when to the left of a -> (or equivalent unicode character) but that's a little context-sensitive.

  Changed 2 years ago by pumpkin

  • cc pumpkingod@… added

  Changed 2 years ago by bos

Trouble is, all of those other lambdas have the Alphabetic property, just like the regular lambda. I have mathematical code that uses identifiers like µ and σ, so λ isn't that much of a stretch.

  Changed 2 years ago by simonmar

  • difficulty changed from Easy (1 hr) to Easy (less than 1 hour)

  Changed 2 years ago by porges

  • failure set to None/Unknown
  • type changed from bug to feature request

I've been thinking that maybe even another arrow might work here, so that we have something like:

    map (x ↦ f x) ys

  Changed 23 months ago by simonmar

  • milestone changed from 6.6.1 to _|_

  Changed 9 months ago by lelf

  • cc anton.nik@… added
Note: See TracTickets for help on using tickets.