We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
import Dice: param_lists
[
"Var" => [DistString],
"App" => [DistUTLC, DistUTLC],
"Abs" => [DistString, DistUTLC],
]
end
DistApp(e1, e2) = construct(DistUTLC, "App", [e1, e2])
DistAbs(s, e) = construct(DistUTLC, "Abs", [s, e])
match(l, [
"Var" => (s) -> DistUInt32(0),
"App" => (e1, e2) -> begin
d1, d2 = ast_depth(e1), ast_depth(e2)
@dice_ite if d1 > d2
DistUInt32(1) + d1
else
DistUInt32(1) + d2
end,
"Abs" => (s, e) -> DistUInt32(1) + ast_depth(e),
])
name, children = ast
if name == "Var"
s, = children
s
elseif name == "Abs"
s, e = children
parens(p > free, "λ$(s).$(utlc_str(e, free))")
elseif name == "App"
e1, e2 = children
parens(
p > fun,
"$(utlc_str(e1, fun)) $(utlc_str(e2, arg))"
)
error("Bad node $(name)")
Dice.jl/qc/examples/lib/dist_utlc.jl
Line 1 in abbd3b6
# TODO: Update # # Define DistUTLC # import Dice: param_lists # struct DistUTLC <: InductiveType end # function param_lists(::Type{DistUTLC})::Vector{Pair{String,Vector{Type}}} # [ # "Var" => [DistString], # "App" => [DistUTLC, DistUTLC], # "Abs" => [DistString, DistUTLC], # ] # end # DistVar(s) = construct(DistUTLC, "Var", [s,]) # DistApp(e1, e2) = construct(DistUTLC, "App", [e1, e2]) # DistAbs(s, e) = construct(DistUTLC, "Abs", [s, e]) # function ast_depth(l::DistUTLC) # match(l, [ # "Var" => (s) -> DistUInt32(0), # "App" => (e1, e2) -> begin # d1, d2 = ast_depth(e1), ast_depth(e2) # @dice_ite if d1 > d2 # DistUInt32(1) + d1 # else # DistUInt32(1) + d2 # end # end, # "Abs" => (s, e) -> DistUInt32(1) + ast_depth(e), # ]) # end # # https://stackoverflow.com/questions/59338968/printing-lambda-expressions-in-haskell # parens(b, s) = if b "($(s))" else s end # @enum Ctx free=0 fun=1 arg=2 # function utlc_str(ast, p=free) # name, children = ast # if name == "Var" # s, = children # s # elseif name == "Abs" # s, e = children # parens(p > free, "λ$(s).$(utlc_str(e, free))") # elseif name == "App" # e1, e2 = children # parens( # p > fun, # "$(utlc_str(e1, fun)) $(utlc_str(e2, arg))" # ) # else # error("Bad node $(name)") # end # end
The text was updated successfully, but these errors were encountered:
No branches or pull requests
import Dice: param_lists
[
"Var" => [DistString],
"App" => [DistUTLC, DistUTLC],
"Abs" => [DistString, DistUTLC],
]
end
DistApp(e1, e2) = construct(DistUTLC, "App", [e1, e2])
DistAbs(s, e) = construct(DistUTLC, "Abs", [s, e])
match(l, [
"Var" => (s) -> DistUInt32(0),
"App" => (e1, e2) -> begin
d1, d2 = ast_depth(e1), ast_depth(e2)
@dice_ite if d1 > d2
DistUInt32(1) + d1
else
DistUInt32(1) + d2
end
end,
"Abs" => (s, e) -> DistUInt32(1) + ast_depth(e),
])
end
name, children = ast
if name == "Var"
s, = children
s
elseif name == "Abs"
s, e = children
parens(p > free, "λ$(s).$(utlc_str(e, free))")
elseif name == "App"
e1, e2 = children
parens(
p > fun,
"$(utlc_str(e1, fun)) $(utlc_str(e2, arg))"
)
else
error("Bad node $(name)")
end
end
Dice.jl/qc/examples/lib/dist_utlc.jl
Line 1 in abbd3b6
The text was updated successfully, but these errors were encountered: