Giter VIP home page Giter VIP logo

Comments (4)

github-actions avatar github-actions commented on June 8, 2024

Thanks for reporting this! To set expectations:

  • Issues are reviewed in batches, so it can take some time to get a response.
  • Ask questions in a community forum. You will get an answer quicker that way!
  • If you experience something similar, open a new issue. We like duplicates.

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

from compiler.

lue-bird avatar lue-bird commented on June 8, 2024

If you need a quick fix, try adding a type annotation to the module-level declaration. Issue seems similar to #1839

from compiler.

mheiber avatar mheiber commented on June 8, 2024

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

from compiler.

Innf107 avatar Innf107 commented on June 8, 2024

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

from compiler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.