我在C#中实现了自己的Promise结构,并想在Haskell中测试这个概念,所以经过一些严重的大脑训练(对我来说还是很新的),我制作了
data Promise f a = PendingPromise f | ResolvedPromise a | BrokenPromise deriving( Show )
class Future p where
later :: (b -> c) -> p (a -> b) b -> p (a -> c) c
resolve :: p (a -> b) a -> a -> p (a -> b) b
instance Future Promise where
later g (PendingPromise f) = PendingPromise (g . f)
later g (ResolvedPromise a) = ResolvedPromise (g a)
resolve (PendingPromise f) a = ResolvedPromise (f …Run Code Online (Sandbox Code Playgroud) haskell ×1