Closed mwalkerwells closed 7 years ago
Maybe<A>
is a semigroup if A
is a semigroup, so you need to pass in a type class instance for A
function getSemigroup<A>(semigroup: Semigroup<A>): Semigroup<Maybe<A>>
// ^
// +--- type class instance for `A`
the signature (and the implementation) is almost a word by word translation of the corrsponding PureScript definition (cfr purescript-maybe)
instance semigroupMaybe :: Semigroup a => Semigroup (Maybe a) where
append Nothing y = y
append x Nothing = x
append (Just x) (Just y) = Just (x <> y)
Note the "Semigroup a =>"
type constraint.
It seemed weird that we're not type checking for Monoid
Actually we are type checking: getSemigroup
returns a Semigroup<Maybe<A>>
Eh, reading this, now it seems so obvious:
Thanks for the clarification!
This may be a n00b question, but what is the reason getSemigroup, getMonoid, _get_Setoid are implemented differently than map / Functor?
Monoid:
Map / Functor
It seemed weird that we're not type checking for Monoid...making me wonder how to implement it differently or better understand why it's not possible.
Type Checks: