svenssonjoel / Sense-VM

Sense-VM has changed name to SynchronVM and is available in a new repository https://github.com/SynchronVM/SynchronVM
MIT License
5 stars 1 forks source link

Remove/inline case expressions when there is only one clause #4

Open Abhiroop opened 3 years ago

Abhiroop commented 3 years ago

Here is an example program:

double : Int -> Int
double n = n * 2

main = double 5

This currently gets desugared to:

let v0 = \ v2 -> case v2 of {
  v1 -> v1 * 2
}
in v0 5

This can be further simplified to:

let v0 = \ v2 -> v2 * 2
in v0 5
Rewbert commented 3 years ago

When functions are desugared pattern matches are turned into case expressions, and right now I believe it assumes there to be more than one pattern. Should be fairly simple (famous last words) to make it recognise that if there is only one pattern and that pattern is a variable, no case is needed.