LoadError: TypeError: Type{...} expression: expected UnionAll, got TypeVar

Hi everyone,

I was writing an Option Monad, and this is what i get from the following line:

m_join{T1<:Option,T2<:Option,T}(x::T1{T2{T}}) = get(None{T}(),x)

and structure of Option is as follows:

    abstract type Option{T} <: Monad end

    type Some{T} <: Option{T}
        value::T
    end

    type None{T} <: Option{T}
    end

I can’t figure out why that error is given? Can someone explain it to me? Thanks

1 Like

If I try the following:

m_join{T}(x::Option{Option{T}}) = get(None{T}(),x)

It gives me the following error:

ERROR: LoadError: MethodError: no method matching m_join(::JHC.Utility.Monads.Some{JHC.Utility.Monads.Some{Int64}})
Closest candidates are:
  m_join(!Matched::JHC.Utility.Monads.TypedFun{JHC.Utility.Monads.TypedFun{T}}) where T at /home/xxx/Projects/JHC/src/Utility/Monads.jl:55
  m_join(!Matched::JHC.Utility.Monads.Option{JHC.Utility.Monads.Option{T}}) where T at /home/xxx/Projects/JHC/src/Utility/Monads.jl:132

This approach seems to work:

function m_join(x::T1) where {T1 <: Option{T2}} where {T2 <: Option{T}} where {T}
    get(None{T}(), x)
end

By the way, the syntax f{T}(x::T) is being deprecated in favor of f(x::T) where {T}.