[Haskell-cafe] Re: Different return type?

Jon Fairbairn jon.fairbairn at cl.cam.ac.uk
Mon Jan 19 05:23:59 EST 2009


"John Ky" <newhoggy at gmail.com> writes:

> Hi,
>
> Possibly a silly question but is it possible to have a function that has a
> different return type based on it's first argument?

Are you sure that's what you really want?

> For instance
>
> data Person = Person { name :: String, ... }
> data Business = Business { business_number :: Int, ...}

data Entity = Person {...} | Business {...}

> key person = name person
> key business = business_number business

data Key = PersonKey String | BusinessKey Int

It seems likely that you are at least sometimes going to
want to pass the result of key to some other function.

...?

-- 
Jón Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk
http://www.chaos.org.uk/~jf/Stuff-I-dont-want.html  (updated 2008-04-26)



More information about the Haskell-Cafe mailing list