hazelgrove / hazel

Hazel, a live functional programming environment with typed holes
http://hazel.org/
MIT License
748 stars 50 forks source link

Constructors that require arguments shouldn't be in patterns without arguments #1309

Open Negabinary opened 4 months ago

Negabinary commented 4 months ago

image

This example should ideally have a static error on the X because it doesn't have an argument.

type T = +X(Int) in
let X = fun x -> X(x) in
?

@disconcision I wonder if you have any ideas how to do this?

disconcision commented 4 months ago

hmm.. would need to decide what the error should be. the example shown doesn't seem fatally problematic, in that even if someone believed X gets bound by the let, it would still have the same result. but if the type had another constructor say Y of the same type, then it would be more confusing. in principle though in such cases would have refutable pattern errors, assuming it's possible to do refutability for arrow typed things

disconcision commented 4 months ago

probably just an arity error for constructors in patterns would do it?

Negabinary commented 4 months ago

It's probably more problematic in a case statement:

image

An arity error would probably do it; we just need to pass some sort of "expected arity" through pattern statics

disconcision commented 4 months ago

not sure we need any more information. we know constructor arities from types in ctx. so:

  1. for pattern ap statics, check if fun pos is constructor with arrow type. inline its statics (ie dont recurse on funpos)
  2. for pattern constructor statics, it must be non arrow type (since we know we didnt pass thru ap)