how to create a lazy tree in Standard ML
-
20-09-2019 - |
Question
I want to implement a lazy tree in Standard ML with
datatype tr = N of int * unit->tr * unit->tr;
I tried to use
fun form k = N(k,fn()=>form(k+1),fn()=>form(k+3));
as a test of concept, but I get error message saying type mismatch.
What would be the proper way of implementing a lazy tree in ML?
Solution
datatype tr = N of int * unit->tr * unit->tr;
This is parsed as
datatype tr = N of (int * unit) -> ( (tr * unit) -> tr)
You want
datatype tr = N of int * (unit->tr) * (unit->tr)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow