flix icon indicating copy to clipboard operation
flix copied to clipboard

Typing of multiple handlers

Open magnus-madsen opened this issue 1 year ago • 4 comments

eff Ask {
    pub def ask(): String
}

eff Say {
    pub def say(s: String): Unit
}

def greeting(): Unit \ {Ask, Say} = 
    let name = do Ask.ask();
    do Say.say("Hello Mr. ${name}")

def main(): Unit \ IO = 
    try {
        try greeting() with Ask {
            def ask(k) = k("Bond, James Bond")
        }
    } with Say {
        def say(s, k) = { println(s); k() }
    }

magnus-madsen avatar Feb 12 '24 14:02 magnus-madsen

I think its the substitution thing again (#7118), The trick is to squeeze variables out of the continuation

eff Ask {
    pub def ask(): String
}

eff Say {
    pub def say(s: String): Unit
}

def greeting(): Unit \ {Ask, Say} =
    let name = do Ask.ask();
    do Say.say("Hello Mr. ${name}")

def main(): Unit \ IO =
    try {
        try greeting() with Ask {
            def ask(k) = {
                let kt: String -> Unit \ Say = k;
                kt("Bond, James Bond")
            }
        }
    } with Say {
        def say(s, k) = { println(s); k() }
    }

JonathanStarup avatar Feb 12 '24 14:02 JonathanStarup

Thanks- I had a student that was caught on this.

magnus-madsen avatar Feb 12 '24 14:02 magnus-madsen

The only thing you have done is to eta expand right?

magnus-madsen avatar Feb 13 '24 08:02 magnus-madsen

Not even, I just type annotated the continuation

JonathanStarup avatar Feb 13 '24 11:02 JonathanStarup