-
Notifications
You must be signed in to change notification settings - Fork 22
Alternative typeclasses when parameter constrained #33
Comments
Maybe export both APIs? export function concat<A>(semigroup: Semigroup<A>): (fx: Maybe<A>, fy: Maybe<A>) => Maybe<A> {
return function concat(fx, fy) {
const x = prj(fx)
const y = prj(fy)
if (x == null) {
return fy
}
if (y == null) {
return fx
}
return of(semigroup.concat(x, y))
}
}
export function getSemigroup<A>(semigroup: Semigroup<A>): Semigroup<Maybe<A>> {
return {
concat: concat(semigroup)
}
}
export function getMonoid<A>(semigroup: Semigroup<A>): Monoid<Maybe<A>> {
return {
empty,
concat: concat(semigroup)
}
} |
That's really nice (I love the typechecking you get from |
Are there other APIs which we should export in your opinion? For example |
I think it makes sense to aim for parity with the Haskell & Purescript preludes |
Sorry for the terseness yesterday! I'll make some PRs (if they'd be well received) for some further instances in the coming days. Also, how about chainRec? The stack safety can't be typechecked AFAIK, but the signature at least could be |
Sure, in the meanwhile I pushed #34 |
🔥 |
What do you think about multiple instances of instance Semigroup (Either a b) where
Left _ <> b = b
a <> _ = a |
Ah yes, we are free to implement several instances of |
Tracking |
Related to #24.
As well as the
getSemigroup
method, one can alsoAnd type check with
(<A>(a: Semigroup<A>) => ({ concat: concat(a) }: Semigroup(<Maybe<A>>))
I slightly prefer this API, but was wondering if you had strong feelings about it / reasons to avoid it
The text was updated successfully, but these errors were encountered: