Skip to content

Instantly share code, notes, and snippets.

@passindro
Created December 21, 2018 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save passindro/2e9a5ff24ed30e4d7588e1eea78188eb to your computer and use it in GitHub Desktop.
Save passindro/2e9a5ff24ed30e4d7588e1eea78188eb to your computer and use it in GitHub Desktop.
power@thautwarm
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