|
|
|
|
|
by consilient
1061 days ago
|
|
Yes you do. `flatMap`ping an array in javascript is using a monad every bit as much as `join`ing a linked list in Haskell. `Promise`s would be monads were it not for the (inexplicable, terrible) decision to make it impossible to nest them. C#'s `IEnumerable<_>` is not quite a monad, but only because it doesn't have a preferred implementation. Pick one, and it's as monadic as `Maybe` or `Either`. And of course function types are always monads. What these languages don't have and Haskell does is a way to talk about all monads, all at once. Instead of replicateM :: forall m a . Monad m => Int -> m a -> m [a]
you have to separately implement replicateArray: <T>(count: number, ts: T[]) => T[][]
replicateFunction: <S, T>(count: number, f: (s: S) => T) => (s: S) => T[]
replicatePromise: <T>(count: number, t: Promise<T>) => Promise<T[]>
and so on. |
|