[Ur] Polymorphic datatype needed too late
Benjamin Barenblat
bbaren at mit.edu
Wed Feb 24 14:07:14 EST 2016
Consider a simple tree in which internal nodes carry structure and
leaves carry data.
datatype tree a =
Leaf of a
| Node of list (tree a)
I can define a mapM operation on such a tree – it simply traverses the
tree and applies a monadic function to each leaf, collecting the
results.
fun mapM
[m ::: Type -> Type] (_ : monad m) [a ::: Type] [b ::: Type]
(f : a -> m b) (tree : tree a)
: m (tree b) =
case tree of
Leaf a =>
b <- f a;
return (Leaf b)
| Node as =>
bs <- List.mapM (mapM f) as;
return (Node bs)
Now, I can create a tree and try some simple operations on it.
val nothing : tree (transaction int) = Node []
val main : transaction page =
result <- mapM (fn x => x) nothing;
return <xml></xml>
When I attempt to compile this, however, I get many ‘unsupported
expression’, ‘unsupported type constructor’, and ‘polymorphic datatype
needed too late’ errors. You can see a complete log of the errors at
http://lpaste.net/8965946982921142272. What do they mean?
I’m running the latest Ur/Web release, 20160213.
Thanks in advance,
Benjamin
More information about the Ur
mailing list