How do I define a data type that only accepts numbers?

后端 未结 3 1105
抹茶落季
抹茶落季 2020-12-30 05:34

I am attempting to create a data type, Point, that takes three numbers for its constructor. Initially, I had written

data Point = Point Double D         


        
3条回答
  •  情深已故
    2020-12-30 05:47

    You can use GADT to specify the constraint:

    {-# Language GADTs #-}
    
    data Point a where
      Point :: (Num a) => a -> a ->  a -> Point a 
    

提交回复
热议问题