You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A function-typed zero-parameter binding in a module is checked as a function of that arity #763
A zero-parameter binding whose declared type is a function is checked as a function of that arity when it sits in a module, but not in an entrypoint. The arrow in the annotation is read as the binding's own parameters, so a let that evaluates to a function value is rejected.
lib/wrap.kex:
module Wrap
type Step = Integer -> Integer
type Wrapper = Step -> Step
around : (Step -> Integer -> Integer) -> Wrapper
let around(body) = { |inner| { |n| body(inner, n) } }
doubled : Wrapper
let doubled = around { |inner, n| inner(n) * 2 }
app/main.kex:
using Wrap
main do
IO.printLine(Wrap.doubled({ |n| n + 1 })(3))
end
$ kex --source-root app --source-root lib app/main.kex
lib/wrap.kex:10:1: [KEXWT-0001]: Warning, type annotation for 'doubled' declares 1 parameter(s) but definition has 0
lib/wrap.kex:10:1: [KEXET-0127]: Error, `doubled` declared to return Integer -> Integer but body returns (Integer -> Integer) -> (Integer -> Integer)
Expected: 8. That is what the same declarations print when they are pasted into the entrypoint above main.
Spelling the type out (doubled : Step -> Step) fails the same way, so the alias is not what triggers it. Only the module placement does.
Found while moving Rodolfo's plugs example routes into a module: logged : Rodolfo.Plug / let logged = Plug.around do |inner, env| ... end is rejected there. The workaround is to drop the annotation and let the type be inferred.
Activity