Created
December 21, 2018 13:53
-
-
Save passindro/2e9a5ff24ed30e4d7588e1eea78188eb to your computer and use it in GitHub Desktop.
power@thautwarm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Fn{A, B} | |
f :: Function | |
end | |
function (f::Fn{A, B})(a :: A) :: B where {A, B} | |
f.f(a) | |
end | |
abstract type Sig end | |
abstract type HKT{S <: Sig, A} end | |
abstract type Functor <: Sig end | |
# interface method: | |
# getsig(::Type{Sig}) :: Sig | |
function fmap(f :: Fn{A, B}, ma :: HKT{F, A}) :: HKT{F, B} where {A, B, F <: Functor} | |
fmap(F, f, ma) | |
end | |
struct Maybe <: Functor # Union{Functor, Applicative, Monad} | |
end | |
struct Some{A} <: HKT{Maybe, A} | |
a :: A | |
end | |
struct None{A} <: HKT{Maybe, A} end | |
function fmap(::Type{Maybe}, f :: Fn{A, B}, ma :: Some{A}) :: HKT{Maybe, B} where {A, B} | |
Some{B}(f(ma.a)) | |
end | |
function fmap(::Type{Maybe}, f :: Fn{A, B}, ma :: None{A}) :: HKT{Maybe, B} where {A, B} | |
None{B}() | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment