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.

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to