Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UCS tracking issue #151

Open
2 of 4 tasks
LPTK opened this issue Nov 22, 2022 · 7 comments · Fixed by #157
Open
2 of 4 tasks

UCS tracking issue #151

LPTK opened this issue Nov 22, 2022 · 7 comments · Fixed by #157
Assignees
Labels
enhancement New feature or request

Comments

@LPTK
Copy link
Contributor

LPTK commented Nov 22, 2022

Issue to track the parts of the UCS implementation that are still incomplete or wrong – please update with more cases as you find them.

Translation

  • Support virtual constructors for pattern matching against tuples. Note as of Jan 2024: We implemented simple tuple pattern in New UCS desugarer and rudimentary PreTyper #194 and we will support advanced tuple patterns, for example, splice tuple patterns, in the near future.
  • Do not duplicate default cases and insert local function definitions instead. Note as of Jan 2024: We paved the road for this in New UCS desugarer and rudimentary PreTyper #194 and we will implement this feature in the near future.

Locations

  • Track scrutinee locations with Scrutinee.Source. (Note: it was removed in new desugarer.)

  • No location reported in:

    fun testF(x) = if x is
      Foo(a) then a
      Foo(a) then a
    //│ ╔══[WARNING] duplicated branch
    //│ ╙──

Reporting

  • Warn when an is test has a single pattern
    Though maybe we shouldn't warn when it's conjuncted with other things, as then the is may be used to bind expressions, as in if xs is x :: xs and mapPartition(f, xs) is (as, bs) and ...
@LPTK LPTK added the enhancement New feature or request label Nov 22, 2022
@LPTK LPTK pinned this issue Dec 1, 2022
@LPTK
Copy link
Contributor Author

LPTK commented Feb 25, 2023

  • hygiene

    :NewParser
    :NewDefs
    :NoJS
    
    class Union<Region>(a: Region, b: Region)
    //│ class Union[Region](a: Region, b: Region)
    
    // * [FIXME:UCS] unhygienically desugars to:
    // | | | | Desugared term: case x of { Union => let x = (x).a in let y = (x).b in x }
    fun hmm(x) =
      if x is Union(x, y) then x
    //│ fun hmm: Union[{b: anything} & 'a] -> 'a
    
    fun hmm(x) =
      if x is Union(z, y) then x
    //│ fun hmm: Union['Region] -> Union['Region]

@LPTK
Copy link
Contributor Author

LPTK commented Mar 3, 2023

  • There's a problem witth he builtin true/false in the current UCS impl
:NewParser
:NewDefs

module Nil
class Cons[A](head: A, tail: Cons[A] | Nil)
//│ module Nil()
//│ class Cons[A](head: A, tail: Cons[A] | Nil)

// FIXME
fun filtermap(f, xs) = if xs is
  Nil then Nil
  Cons(y, ys) and f(ys) is
    false then filtermap(f, ys)
    true then Cons(y, filtermap(f, ys))
    [true, z] then Cons(y, filtermap(f, ys))
//│ ╔══[ERROR] identifier not found: ys
//│ ║  l.26: 	  Cons(y, ys) and f(ys) is
//│ ╙──      	                    ^^
//│ ╔══[ERROR] Type mismatch in application:
//│ ║  l.26: 	  Cons(y, ys) and f(ys) is
//│ ║        	                  ^^^^^^^^
//│ ║  l.27: 	    false then filtermap(f, ys)
//│ ║        	^^^^^^^^^
//│ ╟── reference of type `false` is not an instance of type `number`
//│ ║  l.27: 	    false then filtermap(f, ys)
//│ ╙──      	    ^^^^^
//│ ╔══[ERROR] Type mismatch in application:
//│ ║  l.26: 	  Cons(y, ys) and f(ys) is
//│ ║        	                  ^^^^^^^^
//│ ║  l.27: 	    false then filtermap(f, ys)
//│ ║        	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//│ ║  l.28: 	    true then Cons(y, filtermap(f, ys))
//│ ║        	^^^^^^^^
//│ ╟── reference of type `true` is not an instance of type `number`
//│ ║  l.28: 	    true then Cons(y, filtermap(f, ys))
//│ ╙──      	    ^^^^
//│ ╔══[ERROR] type identifier not found: Tuple#2
//│ ╙──
//│ fun filtermap: ((error | Cons['A] | Nil) -> number & (Cons['A] | Nil) -> error, Cons['A0] | Nil,) -> (Cons['A1] | Nil | error)
//│   where
//│     'A := 'A0
//│     'A0 <: nothing
//│ Code generation encountered an error:
//│   unknown match case: Tuple#2

module True
module False
//│ module True()
//│ module False()

class Pair[A, B](lhs: A, rhs: B)
//│ class Pair[A, B](lhs: A, rhs: B)

fun filtermap(f, xs) = if xs is
  Nil then Nil
  Cons(y, ys) then if f(y) is
    True then filtermap(f, ys)
    False then Cons(y, filtermap(f, ys))
    Pair(True, z) then Cons(z, filtermap(f, ys))
//│ fun filtermap: ('head -> (False | Pair[anything, 'A] | True), Cons['head] | Nil,) -> (Cons['A] | Nil)
//│   where
//│     'head <: 'A

@chengluyu
Copy link
Member

chengluyu commented May 5, 2023

  • Fix unhygienic bindings in HygienicBindings.mls and shared/src/test/diff/ucs/Hygiene.mls
  • Should report warnings in shared/src/test/diff/ucs/Wildcard.mls
  • Proper errors in shared/src/test/diff/ucs/PlainConditionals.mls
  • Some parser failures in shared/src/test/diff/ucs/ParseFailures.mls
  • Support or in shared/src/test/diff/ucs/Or.mls
  • Leading and in shared/src/test/diff/ucs/LeadingAnd.mls
  • Incomplete example in shared/src/test/diff/ucs/JSON.mls

@chengluyu
Copy link
Member

chengluyu commented May 12, 2023

@chengluyu
Copy link
Member

chengluyu commented May 17, 2023

@LPTK
Copy link
Contributor Author

LPTK commented Jul 18, 2023

@LPTK
Copy link
Contributor Author

LPTK commented Feb 19, 2024

  • It seems that this should work, but is currently warned about due to an overly restrictive implementation:
    fun fold(opt, k, d) = if opt is
      None then d
      refined(Some) then k(opt)
      else k(opt)
    //│ ╔══[WARNING] inconsistent refined pattern
    //│ ║  l.67:     None then d
    //│ ║            ^^^^
    //│ ╟── pattern `Some` is refined
    //│ ║  l.68:     refined(Some) then k(opt)
    //│ ║                    ^^^^
    //│ ╟── but pattern `None` is not refined
    //│ ║  l.67:     None then d
    //│ ╙──          ^^^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: 🏗 In progress
Development

Successfully merging a pull request may close this issue.

2 participants