joews / peach

A functional programming language
MIT License
3 stars 0 forks source link

Function clauses must match all possible inputs #9

Open joews opened 7 years ago

joews commented 7 years ago
; passes type check
; should fail because arguments except 1 and 2 do not have a return value
(? 1 "one" 2 "two")

Fixed in #14

; passes type check
; should fail because not all inputs have a function body
(def f
  1 => "one"
  2 => "two")

; OK, because the name can be bound to any input value
(def f
  1 => "one"
  2 => "two"
  _ => "other")

This seems simple enough in this case, but I'm not sure how to do it for all lists:

; should fail
; but how do infinite types (e.g. Number) and finite types (Boolean) differ?
(def f
  (1|t) => "a"
  (h|(2|t)) => "b"
  (h|(i|'(1))) => "c")