How to add a class constraint to a Functor instance declaration in Haskell?

后端 未结 2 489
Happy的楠姐
Happy的楠姐 2021-01-05 23:41

I have defined the following data type:

data Probability a = PD { mass :: [(a, Ratio Int)] } 

Now I want to write that it is an instance of

2条回答
  •  鱼传尺愫
    2021-01-06 00:42

    What you're writing is not a Functor. A Functor's fmap must support arbitrary value types being mapped, not just those that satisfy a certain constraint. You can make it an instance of a more general concept though. For example, the package constrained-categories defines a class of constrained functors.

提交回复
热议问题