You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 23, 2022. It is now read-only.
class<T>Num {
zero :: T,
sub :: T -> T -> T,
neg :: T -> T=subzero
} in
impl NumforInt {
zero =0,
sub x y = x - y
} in
neg 1
direct translation (mlx1-like syntax):
typeNum = ΛT.constraintnumD (T, T -> T -> T, T -> T) inoverload (∀'a. Num'a) inlet zero = numD#0inlet sub = numD#1inlet neg = numD#2in
instance (NumInt) = (0, sub_int, sub zero) in
neg 1
It is possible (by adding the instance itself to the context in translation of rhs of instance) to type and translate this example to OCaml, however, the resulting translation cannot be compiled because a value recursion happens in the dictionary for Num Int.
A possible translation is shown below. Here, numD_37 is occurred in the rhs of its definition.
let zero = (funnumD_22 -> fst3 (numD_22)) inlet sub = (funnumD_29 -> snd3 (numD_29)) inlet neg = (funnumD_36 -> thd3 (numD_36)) inlet numD_37 = (0, sub_int, sub (numD_37) (zero (numD_37))) in
neg (numD_37) (1)
Possible solution
Using lazy evaluation:
let zero = (funnumD_22 -> fst3 (numD_22)) inlet sub = (funnumD_29 -> snd3 (numD_29)) inlet neg = (funnumD_36 -> Lazy.force (thd3 (numD_36))) inletrec numD_37= (0, sub_int, lazy (sub (numD_37) (zero (numD_37)))) in
print_int (neg (numD_37) (1))
The text was updated successfully, but these errors were encountered:
class<T>Eq {
eq :: T -> T -> Bool= \x. \y. not (nexy)
ne :: T -> T -> Bool= \x. \y. not (eqxy)
} in
impl EqforInt {
eq = eq_int
} in
impl EqforFloat {
ne = \x. \y. not (eq_float x y)
} in
ne 12
translation:
typeEq = ΛT.constrainteqD (T -> T -> Bool, T -> T -> Bool) in
overload (∀'a. Eq'a) inlet eq = eqD#0inlet ne = eqD#1in
instance (EqInt) = (eq_int, \x. \y. not (eq x y)) in
instance (EqFloat) = (\x. \y. not (ne x y), \x. \y. not (eq_float x y)) in
ne 12
It seems that lazy evaluation can be applied this case:
let eq = (funeqD_22 -> Lazy.force (fst (eqD_22))) inlet ne = (funeqD_22 -> Lazy.force (snd (eqD_22))) inletrec eqD_37= (lazy eq_int, lazy (funxy -> not (eq (eqD_37) x y))) inletrec eqD_39= (lazy (funxy -> not (ne (eqD_39) x y)), lazy (funxy -> not (eq_float x y))) in
print_bool (ne (eqD_37) (1) (2))
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Problem
an example in mlx1:
direct translation (mlx1-like syntax):
It is possible (by adding the instance itself to the context in translation of rhs of
instance
) to type and translate this example to OCaml, however, the resulting translation cannot be compiled because a value recursion happens in the dictionary forNum Int
.A possible translation is shown below. Here,
numD_37
is occurred in the rhs of its definition.Possible solution
Using lazy evaluation:
The text was updated successfully, but these errors were encountered: