8000 A function-typed zero-parameter binding in a module is checked as a function of that arity · Issue #763 · kexhq/kex · GitHub
[go: up one dir, main page]

Skip to content

A function-typed zero-parameter binding in a module is checked as a function of that arity #763

Open

Description

@akoskovacs

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.

  • Kex: 0.4.0-rc.4 (371bbdf, main)
  • Platform: macOS arm64

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type 3A7B

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0