Partially Applied Types in Haskell

前端 未结 2 939
独厮守ぢ
独厮守ぢ 2021-01-03 06:37

Based on this question, in this code

data Promise a b =  Pending (a -> b) | Resolved b | Broken

instance Functor (Promise x) where
    fmap f (Pending g)         


        
2条回答
  •  梦谈多话
    2021-01-03 07:20

    You are only missing the equations for Resolved and Broken. The only reasonable implementation I can think of is

    fmap f (Resolved x) = Resolved (f x)
    fmap _ Broken = Broken
    

    Other than that, your code is fine.

提交回复
热议问题