A refined implementation of Lightweighted Higher Kinded Types in Julia(via typeclasses/traits)
Author thautwarm
6 Stars
Updated Last
3 Years Ago
Started In
September 2019


Stable Dev Build Status Codecov

It's full featured but has performance issues now.

Also, without structural function types, some advanced polymorhisms might not be that useful, unless you feel okay to annotate functions here and there.

I made this for using tagless-final style in Julia.


using HigherKindedPolymorphisms

abstract type VectSig end
@def_hkt VectSig{T} where T = Vector{T}

using CanonicalTraits
import FunctionWrappers: FunctionWrapper

Fn{A, B} = FunctionWrapper{B, Tuple{A}}
@trait Functor{F} begin
    fmap :: [Fn{A, B}, App{F, A}] where {A, B} => App{F, B}

@implement Functor{VectSig} begin
    fmap(f :: Fn{A, B}, a::App{VectSig, A}) where {A, B} =
        B[f(e) for e in prj(a)] |> inj

f = Fn{Int, String)(string)
a = inj([1, 2, 3])
fmap(f, a) |> prj

#=> ["1", "2", "3"]