elm-in-elm / compiler

Elm compiler written in Elm
https://elm-in-elm.github.io/compiler/
BSD 3-Clause "New" or "Revised" License
388 stars 24 forks source link

Document the "elm type" of kernel functions #58

Open harrysarson opened 5 years ago

harrysarson commented 5 years ago

Kernel functions are defined in JavaScript (no static typing) but can be called from elm (static typing) and thus have some sort of implicit type signature.

For example the kernel function

https://github.com/elm/core/blob/665624859a7a432107059411737e16d1d5cb6373/src/Elm/Kernel/Basics.js#L17

var _Basics_remainderBy = F2(function(b, a) { return a % b; });

is called in elm

https://github.com/elm/core/blob/665624859a7a432107059411737e16d1d5cb6373/src/Basics.elm#L533-L535

remainderBy : Int -> Int -> Int
remainderBy =
  Elm.Kernel.Basics.remainderBy

and so we deduce that a and b must have type Int and the function returns an Int*.


However, other functions have much stranger signatures. For example, what is the type signature for stepperBuilder here?

https://github.com/elm/core/blob/665624859a7a432107059411737e16d1d5cb6373/src/Elm/Kernel/Platform.js#L35

function _Platform_initialize(flagDecoder, args, init, update, subscriptions, stepperBuilder)

It is far from clear. Looking at the use of stepperBuilder

var stepper = stepperBuilder(sendToApp, model);

stepperBuilder is function that takes two arguments (which is not allowed in elm) but what are the types of those arguments? What is the return type?

If elm-in-elm is able to implement kernel code for targets other than javascript, or move logic from "kernel space" into "elm space" then we first need to solidly document all these implicit type signatures.


I am proposing an effort to compliment the documentation written as part of #57 with type signatures.


Janiczek commented 5 years ago

I agree it would be helpful to end up with a concise list of functions other targets have to implement, and their types. :+1:

Just want to check - we don't need to document all JS functions, just the ones exposed by immediate usage from *.elm files, right? (Transitive dependencies are implementation detail and the other targets might choose to not take the same approach to implement the immediate dependencies.)

harrysarson commented 5 years ago

All functions used by *.elm files and all functions that can be called by compiler generated js :+1: