[Haskell-cafe] lists with mixed types

Anatoly Yakovenko aeyakovenko at gmail.com
Sat Jun 16 01:56:46 EDT 2007


If I define something like this:

data Bar = Bi Int
         | Bf String
         deriving Show

data Foo = Fi Int
         | Fs Float
         deriving Show

func::Foo -> Bar
func (Fi xx) = Bi xx
func (Fs ff) = Bf (show ff)

I can do:
> map func [(Fi 1), (Fs 2.0)]
[Bi 1,Bf "2.0"]

but what i really want to do is just do
map func [1, 2.0]
[1, "2.0"]

I understand that this is impossible in haskell, but why cant the
compiler generate the Foo and Bar data types for me and just require
that i have a func defined for Int -> Int and Float -> String?


More information about the Haskell-Cafe mailing list