[nem-bug] [Nemerle 0000539]: Failed CheckSTV with monad code

feedback at nemerle.org feedback at nemerle.org
Wed Oct 5 16:20:50 CEST 2005


A NOTE has been added to this issue.
======================================================================
<http://nemerle.org/bugs/view.php?id=539> 
======================================================================
Reported By:                nazgul
Assigned To:                
======================================================================
Project:                    Nemerle
Issue ID:                   539
Category:                   Compiler
Reproducibility:            always
Severity:                   minor
Priority:                   high
Status:                     confirmed
======================================================================
Date Submitted:             09-28-2005 18:40 CEST
Last Modified:              10-05-2005 16:20 CEST
======================================================================
Summary:                    Failed CheckSTV with monad code
Description: 
public interface IMonad[A]
{
     /*
      * a static unit (return in haskell) method should be part of the
interface
      * unit(o:object):Monad --could just be the ctor
      */
    bind[B](f : (A -> IMonad[B])) : IMonad[B];
}

public class Continuation[R,A]:IMonad[A]
{
    
    private value : (A -> R) -> R;
    public static return (a : A): Continuation[R,A]{ 
        Continuation(fun(k : A -> R){k(a)}) 
    }
    public static CallCC[B](f : (A -> Continuation[R,B]) ->
Continuation[R,A]) : Continuation[R,A]{
        Continuation(fun(k : A -> R)
                     {
                         def g(a : A)
                         {
                             Continuation(fun(_: B -> R){k(a)})
                         };
                         (f(g)).value(k)
                     })
    }
    public this(f : (A -> R) -> R ){ 
        value = f;
    }
    public bind[B](f : (A -> IMonad[B])) : IMonad[B]{
        Continuation(fun(k : B -> R)
                     { 
                         value(fun (a : A)
                               {
                                   def g = f(a) :> Continuation[R,B]; 
                                   g.value(k) 
                               })
                     })
    }
    public run(f : A -> R):R
    {
       value(f)
    }
    
}



public class Driver{
    public static Main():void{
      
        def myTry[A,B] (f : ((A -> Continuation[B,A]) * A)  ->
Continuation[B,A], x : A){
null : Continuation [int, int]
          /*
            Continuation.CallCC(fun(e)
                                {
                                    f(e,x)
                                })
            */
        };
        def simpleTryEntry(_ : int -> Continuation[int,int], _ : int){
          null 
        }

        //System.Console.WriteLine(myTry(tryEntry,
7).run(fun(a){a}).ToString())
        System.Console.WriteLine(myTry(simpleTryEntry,
7).run(fun(a){a}).ToString())
    }
}


======================================================================

----------------------------------------------------------------------
 malekith - 10-05-05 16:20 
----------------------------------------------------------------------
The problem is that a polymorphic functions is used just once, and hence
inlined. As this is not very common situation, I guess I will just prevent
inlining in this case.

Issue History
Date Modified  Username       Field                    Change              
======================================================================
09-28-05 18:40 nazgul         New Issue                                    
10-03-05 19:34 nazgul         Status                   new => confirmed    
10-04-05 21:01 nazgul         Priority                 normal => high      
10-05-05 16:20 malekith       Note Added: 0000989                          
======================================================================




More information about the bugs mailing list