You may find these related discussions useful. They have pointers to discussions in issues, and other discussions on this forum, and previously Google groups, etc.
I have some predicate types that have a predicate field. I want my fields to be of type (t::T -> Bool). Instead they’re of type Function. It all looks like this:
abstract Foo{T}
type unP{T} <: Foo{T}
p::Function
end
un = unP{Int}(t::Int -> t > 0); println(typeof(un.p))
type andP{T} <: Foo{T}
p::Vector{Function}
end
and = andP{Int}([t -> t > 0, t -> t < 10]); println(typeof(and.p))
and.p[1](1) |> println
type AndP{T} <: Foo{T}
p::Tuple{Foo{T},Foo{T}}
end
And = AndP((un,un)); println(t…
I’ve ran into multiple scenarios now where I’d like to pass a function as an argument to another function, but I want to make sure it conforms to a certain type signature.
For example:
function dosomething(times::Int,doit::Function)
for i=1:times
doit(i)
end
end
What I’d like to do in the above example is restrict doit() to any Function that takes a single Int argument. Obviously, I could just document that in the usage, and “hope” that it works out. But, I think it would be …
(continuing this from https://github.com/JuliaLang/julia/issues/17168#issuecomment-275004495 )
Haskell’s lack of “dynamic” multiple dispatch is because it’s a static language
There’s no formal definition of what characterizes a static language, but I don’t think this necessarily part of it. Julia can be defined to fit into the “static language” category[1] (it can be compiled to native code without need for an interpreter) and has multiple dispatch. Java doesn’t have multiple dispatch and isn…
Most concepts in Julia have first-class object representations. However, currently dispatch is arguably not one of those things. This hasn’t been a huge issue so far, since people have sometimes found various workarounds. But I want to propose adding a sort of explicit arrow type. I think this would also be especially helpful in dealing with the new world update logic.
This also would be an answer to Helping julia with runtime dispatch/arrowtypes .
Current developments in this direction include…