joews / peach

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

Add type annotations #17

Open joews opened 7 years ago

joews commented 7 years ago

Some ideas:

# :, "of" or nothing between name and annotation?
# or parens?
# fib of Number -> Number =
# fib : Number -> Number =
# fib Number -> Number =
# fib (Number -> Number) = 

fib : Number -> Number =
  0 -> 1
  1 -> 1
  x -> + (fib (- x 1)) (fib (- x 2))

x of String
x of String = `hi`

map (x -> { + x 2 }) [1 2 3 4]

_peach-filter : (T -> Boolean) -> List<T> -> List<T> -> List<T>
  (_, [], done) => done
  (fn, [head|tail], done) => 
    if (fn head) 
      _peach-filter fn tail [head|done]
    else
      _peach-filter fn tail done

peach-filter of (T -> Boolean) -> List<T> -> List<T> =
  (fn, list) => reverse (_peach-filter fn list [])

(peach-filter (x => (>= x 2)) '(1 2 3 4))