effekt icon indicating copy to clipboard operation
effekt copied to clipboard

Machine: Handle evidence

Open marzipankaiser opened this issue 1 year ago • 10 comments

Handle evidence and use it to execute effect operations in the correct context.

Is not yet correctly implemented in the llvm backend (number of stacks to pop is ignored), so widely untested.

marzipankaiser avatar Oct 04 '22 09:10 marzipankaiser

For some reason, fibonacci.effekt works on my machine but fails in the CI.

marzipankaiser avatar Oct 04 '22 09:10 marzipankaiser

Also, while I wanted to use infixAdd for my first draft, resolving that Symbol in the Context sometimes failed, so I added EviAdd.

marzipankaiser avatar Oct 04 '22 09:10 marzipankaiser

For some reason, fibonacci.effekt works on my machine but fails in the CI.

Maybe stack size?

b-studios avatar Oct 04 '22 09:10 b-studios

If we absolutely have to add EviAdd then I would call it something like ComposeEvidence.

b-studios avatar Oct 04 '22 10:10 b-studios

If we absolutely have to add EviAdd then I would call it something like ComposeEvidence.

Ah, yes, that's a better name.

marzipankaiser avatar Oct 04 '22 10:10 marzipankaiser

https://github.com/effekt-lang/effekt/pull/164/commits/f85fb62a1d8a3d6657680bffab0cc3a98248403a uses "infixAdd" instead of ComposeEvidence. I'm not sure if that is preferable?

Note: the current implementation would break if the type of infixAdd changed from (Int, Int): Int.

marzipankaiser avatar Oct 04 '22 12:10 marzipankaiser

@phischu tested it on his machine and it was indeed the stack limit being reached.

marzipankaiser avatar Oct 04 '22 13:10 marzipankaiser

I have now semi-splitted out evidence. It is still synonymous int in most places (i.e. machine.builtins.Evidence is machine.Type.Evidence etc), but can be used as if it weren't (there is a type alias Evidence, and builtins.Here (=0) and builtins.There(_) (=_+1) work for both construction and patterns).

marzipankaiser avatar Oct 06 '22 11:10 marzipankaiser

Why does There take another evidence? It should just alias the number 1 IIUC.

b-studios avatar Oct 07 '22 07:10 b-studios

I think both are reasonable. I understand Here and There as the constructors of the evidence type, so There just says "outside of the current region" and still needs specification/proof as to where exactly (like with e.g. Data.List.Relation.Unary.Any etc in Agda).

I am not strongly opposed to changing it to There : Evidence = 1, although I think it's nicer this way, as it allows to construct all possible evidence values without using + (on Int).

marzipankaiser avatar Oct 09 '22 19:10 marzipankaiser

After rethinking it, I changed There to be 1 now.

marzipankaiser avatar Nov 07 '22 14:11 marzipankaiser

(and rebased to current master)

marzipankaiser avatar Nov 07 '22 14:11 marzipankaiser