Skip to content

Trouble with Implicit Parameters #39

@JoergWMittag

Description

@JoergWMittag

I was toying around with Magpie's functional programming features and ran into some trouble with Implicit Parameters. I have a repository where I keep a simple implementation of the Church Encoding of lists in the λ-calculus in various languages and wanted to add a Magpie implementation.

Originally, I had written this:

val kons = fn(hd, tl) fn if _ then hd else tl
val virst = fn _ call(true )
val rrest = fn _ call(false)

val lstt  = kons call(1, kons call(2, nothing))

virst call(rrest call(lstt))

Which I thought should work (although I admit I didn't look into it too deeply), but I always get an error:

Uncaught NoVariableError: Could not find a variable named "_" (lambdaconscarcdr.mag (line 3, col 16-17)).

I am also befuddled by the fact that that the error appears on line 3, but not on the equivalent line 2. However, when I fix the error on line 3 by making the parameter explicit, it then reports line 1 as erroneous. When I fix that, the error moves to line 2.

The explicit version works:

val kons = fn(hd, tl) fn(x) if x then hd else tl
val virst = fn(l) l call(true )
val rrest = fn(l) l call(false)

val lstt  = kons call(1, kons call(2, nothing))

virst call(rrest call(lstt))

I am using the latest version of the Java interpreter at the moment, since the documentation says that the C++ VM is still missing some language features. (And also, I was lazy and I already had a Java environment set up anyway.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions