[Haskell-cafe] Proposal: Polymorphic typeclass and Records

Wvv vitea3v at rambler.ru
Wed Aug 28 22:05:35 CEST 2013


Let we have data in one module as this:

	data Person  = Person  { personId :: Int, name :: String }
	data Address a = Address { personId :: Int, address :: String , way :: a}

It was discussed a lot in topics "OverloadedRecordFields"

This is an alternative:
Let we have polymorphic typeclass:

          class Record{f} a b | a -> b where
	      f :: a -> b

so, compiler could create instances for our data as:

	instance Record{personId} Person Int where
		personId (Person x _) = x

	instance Record{personId} (Address a) Int where
		personId (Address x _ _) = x	

	instance Record{way} (Address Int) Int where
		way (Address _ _ x) = x	

and we could use this:

        p:: Record {personId} r Int => r -> Int
        p = personId
        

What do you think about this?



--
View this message in context: http://haskell.1045720.n5.nabble.com/Proposal-Polymorphic-typeclass-and-Records-tp5735096.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.




More information about the Haskell-Cafe mailing list