On 01/04/2017 05:40 AM, Marco Maggesi wrote:
I'm trying to figure out what is wrong with this program:

fun mapseq [m ::: Type -> Type] (_ : monad m) [t ::: Type]
            (f : t -> m unit) (ls : list t)
   : m unit
   = case ls of
      [] => return ()
    | h :: t => f h; mapseq f t

val l = "a" :: "b" :: "c" :: []

fun main () =
   mapseq (fn s => debug s) l;
   return <xml/>

Shallow answer: that function is already in the standard library as [List.app], and it will work in your example if used instead of [mapseq].

Deeper answer: you've run into the general heuristic nature of the compiler optimizations to remove all uses of polymorphism, where the compiler will give up if any polymorphism remains in the end, in server-side code. These optimizations generally work best when all of a function's type parameters appear before any value parameters. So, swapping [t] and the [monad] argument does the trick (without requiring any changes to the actual calls).

_______________________________________________
Ur mailing list
[email protected]
http://www.impredicative.com/cgi-bin/mailman/listinfo/ur

Reply via email to