[Haskell-cafe] Re: Different return type?

Chung-chieh Shan ccshan at post.harvard.edu
Mon Jan 19 07:48:07 EST 2009


John Ky <newhoggy at gmail.com> wrote in article <bd4fcb030901181744i2b26172bv2328974ff911fb4e at 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!~



More information about the Haskell-Cafe mailing list