Alex Ferguson: 
>Kevin Atkinson:
>> I take it that you are happy with names such as:  [long list]
>
>Yes.  Certainly I'm more than happy that types with completely different
>signatures have different names.

I also prefer to keep the names distinct when the meanings are distinct.  I
got to thinking about zip and unzip, zip2 and unzip2, etc. which gave a
feeling of not being so distinct.  Turns out, it's currying which prevents
their signatures from being combined.  Non-curried versions can be defined
on general tuples, with just one pair of names:

    class Zippable tOfLists tsInList
      where
        zip' :: tOfLists -> [tsInList]
        unzip' :: [tsInList] -> tOfLists
    instance Zippable () ()
      where
        zip' () = repeat ()
        unzip' _ = ()
    instance Zippable ([t],[u],[v]) (t,u,v)
      where
        zip' (x:xs, y:ys, z:zs) = (x,y,z): (zap (xs, ys, zs))
        zip' _ = []
        unzip' ((x,y,z):more) = (x:xs, y:ys, z:zs) 
          where
            (xs, ys, zs) = unzip' more
    instance Zippable ([t]) (t)
    instance Zippable ([t],[u]) (t,u)
    instance Zippable ([t],[u],[v],[w]) (t,u,v,w)
    etc. left as an exercise.

Thus, the uglier cases on Kevin Atkinson's list can be addressed within
Haskell's current overloading system.

--
Scott Turner
[EMAIL PROTECTED]       http://www.ma.ultranet.com/~pkturner



Reply via email to