John Ky <newho...@gmail.com> wrote in article 
<bd4fcb030901181744i2b26172bv2328974ff911f...@mail.gmail.com> in 
gmane.comp.lang.haskell.cafe:
> data Person = Person { name :: String, ... }
> data Business = Business { business_number :: Int, ...}
>
> key person = name person
> key business = business_number business

Let's make this concrete:

  data Person = Person { name :: String, age :: Integer }
  data Business = Business { business_number :: Int, revenue :: Double }

  key person = name person
  key business = business_number business

Even without dependent types, you can do the following (but of course,
you lose some syntactic sugar for records):

  data Individual k v = Individual { key :: k, value :: v }
  type Person = Individual String Integer
  type Business = Individual Int Double

  name :: Person -> String
  name = key

  age :: Person -> Integer
  age = value

  business_number :: Business -> Int
  business_number = key

  revenue :: Business -> Double
  revenue = value

-- 
Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig
May all beings be well and happy!~

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

Reply via email to