elm / compiler

Compiler for Elm, a functional language for reliable webapps.
https://elm-lang.org/
BSD 3-Clause "New" or "Revised" License
7.48k stars 659 forks source link

Transmute value to arbitrary type with mutually recursive functions #2274

Open 1derless opened 1 year ago

1derless commented 1 year ago

Quick Summary: Mutually recursive functions can be used to transmute a value to an arbitrary type.

SSCCE

-- repl says f has type `a -> b -> c`
f x y = g x y
g x y = if False then f x y else y

eraseType : a -> b
eraseType x = f () x

Additional Details

Ellie: https://ellie-app.com/jr8JcxccdXba1

I think the types of f and g should be a -> b -> b, and my Haskell compiler (ghc) agrees.

In addition, attempting to print the type of g in the repl causes the crash in the mutual recursion-related issue #2207.

github-actions[bot] commented 1 year ago

Thanks for reporting this! To set expectations:

Finally, please be patient with the core team. They are trying their best with limited resources.