Open Innf107 opened 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.
If you need a quick fix, try adding a type annotation to the module-level declaration. Issue seems similar to https://github.com/elm/compiler/issues/1839
Re
The reason I even found this is that the error messages reported by both GHC and OCaml are quite poor.
What's the OCaml error message? This OCaml translation compiles and runs on at least OCaml 4.13.1 and 5.0.0:
let f x =
let _g : (('a -> unit) -> unit) = fun h -> h x
in x
https://try.ocamlpro.com/#code/let'f'x'=!let'_g':'(($,a'-$.'unit)'-$.'unit)'='fun'h'-$.'h'x!in'x
This is quite subtle, but the OCaml type you wrote is not actually equivalent to the one in Elm.
'a
variables are not implicitly quantified type variables like in Elm or Haskell. They are actually just stand-ins for unification variables, which are closer to _a
with PartialTypeSignatures in Haskell.
In other words, the following will compile and define a function f : Int -> int
let f : 'a -> 'a = fun x -> x + 1
To get the fully polymorphic behavior like in Elm or Haskell, one needs to use an explicit quantifier
let f x =
let g : 'a. ('a -> unit) -> unit =
fun h -> h x
in x
This generates the "fantastic" error message
Error: This definition has type ('a -> unit) -> unit which is less general than
'a0. ('a0 -> unit) -> unit
Quick Summary: The compiler crashes in compiler/src/Type/Solve.hs:206:15 when checking the body of
g
, which unifies a skolem bound in the type ofg
(a
) with a unification variable from the definition off
(the type ofx
)SSCCE
Additional Details
This should result in an error, ideally with a nice error message. The reason I even found this is that the error messages reported by both GHC and OCaml are quite poor.
Error message