[Ur] Some utility functions to add to base libs?
Edward Z. Yang
ezyang at MIT.EDU
Thu May 17 15:03:29 EDT 2012
Here are two that I found useful:
fun mapXiM [m ::: (Type -> Type)] (_ : monad m) [a] [ctx ::: {Unit}] (f : int -> a -> m (xml ctx [] [])) : list a -> m (xml ctx [] []) =
let
fun mapXiM' i ls =
case ls of
[] => return <xml/>
| x :: ls =>
this <- f i x;
rest <- mapXiM' (i+1) ls;
return <xml>{this}{rest}</xml>
in
mapXiM' 0
end
fun liftM2 [m ::: (Type -> Type)] (_ : monad m) [a] [b] [c] (f : a -> b -> c) (mx : m a) (my : m b) : m c =
x <- mx;
y <- my;
return (f x y)
It would also be nice for us Haskell folks if we had a 'val liftM = mp' somewhere too :-)
Edward
More information about the Ur
mailing list