
These functions have their arguments reversed when compare to e.g. Map For example Data.HashTable.lookuphttp://haskell.org/ghc/docs/latest/html/libraries/base/Data-HashTable.html#v... :: HashTablehttp://haskell.org/ghc/docs/latest/html/libraries/base/Data-HashTable.html#t... key val -> key -> IOhttp://haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#t%3AIO (Maybehttp://haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#t%3AM... val) Data.Map.lookuphttp://hackage.haskell.org/packages/archive/containers/0.2.0.0/doc/html/Data... :: Ordhttp://hackage.haskell.org/packages/archive/base/4.0.0.0/doc/html/Data-Ord.h... key => key -> Maphttp://hackage.haskell.org/packages/archive/containers/0.2.0.0/doc/html/Data... key val -> Maybehttp://hackage.haskell.org/packages/archive/base/4.0.0.0/doc/html/Data-Maybe... val I find this a bit odd. Is this by design?

It is a bit odd. I'd suggest improvements (particularly implementing "carding" strategies) should be uploaded to hackage. -- Don bugfact:
These functions have their arguments reversed when compare to e.g. Map
For example
Data.HashTable.lookup :: HashTable key val -> key -> IO (Maybe val)
Data.Map.lookup :: Ord key => key -> Map key val -> Maybe val
I find this a bit odd. Is this by design?
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Tue, Apr 7, 2009 at 3:23 PM, Peter Verswyvelen
These functions have their arguments reversed when compare to e.g. Map For example Data.HashTable.lookup :: HashTable key val -> key -> IO (Maybe val)
Data.Map.lookup :: Ord key => key -> Map key val -> Maybe val
I find this a bit odd. Is this by design?
Speaking of design. I think the version in HashTable would be better for partial application in most cases. With that version you can partially apply the hashtable you want to use and then get a function (key -> IO (Maybe val)). So I think most uses wouldn't need to sneak in a flip. Jason

On Wed, 8 Apr 2009, Peter Verswyvelen wrote:
These functions have their arguments reversed when compare to e.g. Map For example
Data.HashTable.lookup :: HashTable key val -> key -> IO (Maybe val)
Data.Map.lookup :: Ord key => key -> Map key val -> Maybe val
For my taste, Data.Map.lookup has the wrong parameter order, since I often need the same Map with different keys and not vice versa. The HashTable.lookup parameter order can also be read as mapping a Map to the function it represents. I mean (HashTable key val) and (Map key val) represent functions of type (key -> val) and you can write: Data.HashTable.lookup :: HashTable key val -> (key -> IO (Maybe val)) http://www.haskell.org/haskellwiki/Parameter_order

yes I agree. It seems to be mentioned here too http://www.haskell.org/haskellwiki/Parameter_order On Wed, Apr 8, 2009 at 12:38 AM, Henning Thielemann < lemming@henning-thielemann.de> wrote:
On Wed, 8 Apr 2009, Peter Verswyvelen wrote:
These functions have their arguments reversed when compare to e.g. Map
For example
Data.HashTable.lookup :: HashTable key val -> key -> IO (Maybe val)
Data.Map.lookup :: Ord key => key -> Map key val -> Maybe val
For my taste, Data.Map.lookup has the wrong parameter order, since I often need the same Map with different keys and not vice versa. The HashTable.lookup parameter order can also be read as mapping a Map to the function it represents. I mean (HashTable key val) and (Map key val) represent functions of type (key -> val) and you can write: Data.HashTable.lookup :: HashTable key val -> (key -> IO (Maybe val))

Peter Verswyvelen wrote:
These functions have their arguments reversed when compare to e.g. Map For example
Data.HashTable.lookup :: HashTable key val -> key -> IO (Maybe val)
Data.Map.lookup :: Ord key => key -> Map key val -> Maybe val
I find this a bit odd. Is this by design?
I'd guess it's due more to antiquity than to intention. Data.Map mirrors the Prelude, along with almost everyone else: GHC.List.lookup :: (Eq a) => a -> [(a, b)] -> Maybe b Data.IntMap.lookup :: (Monad m) => Data.IntMap.Key -> IntMap a -> m a Data.Trie.lookup :: ByteString -> Trie a -> Maybe a Data.Set.member :: (Ord a) => a -> Set a -> Bool As a design issue, I think the dominant order is better for partial application since they make good arguments to Control.Monad.State.gets and similar state-like HOFs. Considering the IO ugliness of HashTable, Jason Dagit may have a point though. As I recall, this discussion has lead to flame wars in the past. -- Live well, ~wren

On Wed, Apr 8, 2009 at 12:46 AM, wren ng thornton
As a design issue, I think the dominant order is better for partial application since they make good arguments to Control.Monad.State.gets and similar state-like HOFs. Considering the IO ugliness of HashTable, Jason Dagit may have a point though. As I recall, this discussion has lead to flame wars in the past.
Okay. I guess there's no clear winner here when it comes to argument order. And no need to waste energy on another flame war :-)

On Tue, Apr 7, 2009 at 3:49 PM, Peter Verswyvelen
On Wed, Apr 8, 2009 at 12:46 AM, wren ng thornton
wrote: As a design issue, I think the dominant order is better for partial application since they make good arguments to Control.Monad.State.gets and similar state-like HOFs. Considering the IO ugliness of HashTable, Jason Dagit may have a point though. As I recall, this discussion has lead to flame wars in the past.
Okay. I guess there's no clear winner here when it comes to argument order. And no need to waste energy on another flame war :-)
Especially here with Haskell. Just use flip if the arguments come in the wrong order. Jason

Jason Dagit wrote:
Peter Verswyvelen wrote:
wren ng thornton wrote:
As a design issue, I think the dominant order is better for partial application since they make good arguments to Control.Monad.State.gets and similar state-like HOFs. Considering the IO ugliness of HashTable, Jason Dagit may have a point though. As I recall, this discussion has lead to flame wars in the past.
Okay. I guess there's no clear winner here when it comes to argument order. And no need to waste energy on another flame war :-)
Especially here with Haskell. Just use flip if the arguments come in the wrong order.
I gotta say, I do enjoy the natural transformations Foo a b -> (a -> b) though. Perhaps Data.Map is right to have both lookup and (!)--- even though everyone's abandoned that due to the ugliness of qualified symbolic names. Is there a class somewhere which provides co-arr? There'd be a lot of instances for it[1]. Though the proper abstract nonsense should allow defining Foo a b -> F(a -> G b) for F and G other than Id (namely IO and Maybe for the functions under discussion). The problem here is the same as the (>>=) vs (=<<) issue for monads. On the one hand there's a pipelining or concatenative idiom, and on the other hand there's an applicative idiom. Both are declarative, both are functional, and both are (under different circumstances) natural. Yet we don't have a general solution for incorporating both styles, other than relegating one style to using flip everywhere. Hence the flames, since everyone wants to paint their own bikeshed, and noone wants to be a second-class citizen. [1] http://haskell.org/hoogle/?hoogle=a+b+c+-%3E+%28b+-%3E+c%29 -- Live well, ~wren

On 8 Apr 2009, at 00:46, wren ng thornton wrote:
Peter Verswyvelen wrote:
These functions have their arguments reversed when compare to e.g. Map For example Data.HashTable.lookup :: HashTable key val -> key -> IO (Maybe val) Data.Map.lookup :: Ord key => key -> Map key val -> Maybe val I find this a bit odd. Is this by design?
As a design issue, I think the dominant order is better for partial application since they make good arguments to Control.Monad.State.gets and similar state-like HOFs. Considering the IO ugliness of HashTable, Jason Dagit may have a point though. As I recall, this discussion has lead to flame wars in the past.
To add my 2¢ to this one – The arguments for each one can be put across as this: • I prefer (M a b) -> a -> b, because we can do functional programming in it more easily. • I prefer a -> (M a b) -> b, because we can do stateful programming in it more easily. Perhaps we need to remember what kind of language Haskell is – yes it's an excellent imperative language, but when it gets down to it, it's functional, and maybe we should try to keep it that way. To add support to the other argument though – I think the stateful version reads better when used fully applied – it reads as lookup this key in this map. The reverse doesn't read so well in english, the best I can think of is, transform this map into a function and apply it, but that doesn't actually include the word lookup anywhere. Bob

wren ng thornton
Data.HashTable.lookup :: HashTable key val -> key -> IO (Maybe val) Data.Map.lookup :: Ord key => key -> Map key val -> Maybe val
I'd guess it's due more to antiquity than to intention.
I am fairly sure that FiniteMap, which preceeded Data.Map, had the same parameter order as HashTable. -k -- If I haven't seen further, it is by standing in the footprints of giants
participants (7)
-
Don Stewart
-
Henning Thielemann
-
Jason Dagit
-
Ketil Malde
-
Peter Verswyvelen
-
Thomas Davie
-
wren ng thornton