[Haskell-beginners] Structural restrictions in type constructor

Imants Cekusins imantc at gmail.com
Mon Jun 22 11:29:36 UTC 2015


we could use pattern matched constructor:

module PairsMatched where

data MyP t = MyP (t,t)(t,t) deriving Show


myP_ctor:: Eq t => (t,t)->(t,t)->MyP t
myP_ctor (a1,a2) (a3,a4)
   | a1 == a4 && a2 == a3 = MyP (a1,a2) (a3,a4)
   | otherwise = error "mismatched pairs"


More information about the Beginners mailing list