How to model mixins / multiple interfaces in Haskell?

后端 未结 5 1685
闹比i
闹比i 2021-02-08 11:31

I came across this question on modeling inheritance in Haskell and it reminded me that I have a little more complicated version of the same problem. I\'ll adopt the example from

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-08 11:57

    Are you aware that a Tuple with arity of 2 has a Functor instance, which maps over the second item? We can use it to our benefit.

    data PositionAndVelocity = PositionAndVelocity Vec3 Vec3
    data Colour = ...
    
    f1 :: (PositionAndVelocity, Camera) -> ...
    f2 :: (Colour, Camera) -> ...
    

提交回复
热议问题