[CakeML] Polymorphic type annotation
Mário Pereira
Mario.Parreira-Pereira at lri.fr
Wed May 2 08:59:58 UTC 2018
Dear list,
I am currently running some experiences around the CakeML compiler.
I ran across some difficulties when trying to annotate function
arguments with polymorphic types. Take for instance the CPS version of a
function that computes the height of a binary tree:
datatype 'a tree = Leaf | Node of 'a tree * 'a * 'a tree
fun height t (k: int -> int) =
case t of
Leaf => k 0
| Node l _ r =>
height l (fn hl =>
height r (fn hr => 1 + max hl hr))
This program is accepted by CakeML. However, I would like to write the
following more general version of it:
fun height t (k: int -> 'a) =
case t of
Leaf => k 0
| Node l _ r =>
height l (fn hl =>
height r (fn hr => 1 + max hl hr))
which gives me "### ERROR: type error Bad type annotation in pattern".
I see the error is not related to the arrow type, as the polymorphic
identity function 'fun id (x: 'a) = x' is also rejected.
Am I doing something wrong with the syntax of type annotations ?
Best regards
--
Mário Pereira
More information about the Users
mailing list