Skip to content

A refined implementation of Lightweighted Higher Kinded Types in Julia(via typeclasses/traits)

License

Notifications You must be signed in to change notification settings

thautwarm/HigherKindedPolymorphisms.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HigherKindedPolymorphisms

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.

Usage

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}
end

@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
end

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

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

About

A refined implementation of Lightweighted Higher Kinded Types in Julia(via typeclasses/traits)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages