From simonmarhaskell at gmail.com Fri Nov 21 03:47:23 2008 From: simonmarhaskell at gmail.com (Simon Marlow) Date: Fri Nov 21 03:41:24 2008 Subject: patch applied (haskell-prime-status): Add simonpj's ImportShadowing proposal Message-ID: <20081121084723.GA10580@haskell.galois.com> Fri Nov 21 00:46:48 PST 2008 Simon Marlow * Add simonpj's ImportShadowing proposal M ./status.hs +5 View patch online: http://darcs.haskell.org/haskell-prime-status/_darcs/patches/20081121084648-12142-366f7d72d3fc6ad4a6dee06c87983ac9aea7a981.gz From circularfunc at gmail.com Thu Nov 27 13:59:08 2008 From: circularfunc at gmail.com (circ ular) Date: Thu Nov 27 13:52:50 2008 Subject: Suggestion: Syntactic sugar for Maps! Message-ID: I suggest Haskell introduce some syntactic sugar for Maps. Python uses {"this": 2, "is": 1, "a": 1, "Map": 1} Clojure also use braces: {:k1 1 :k2 3} where whitespace is comma but commas are also allowed. I find the import Data.Map and then fromList [("hello",1), ("there", 2)] or the other form that I forgot(because it is to long!) to be to long... So why not {"hello": 1, "there": 2} ? Best regards Cirfan From dons at galois.com Thu Nov 27 14:03:41 2008 From: dons at galois.com (Don Stewart) Date: Thu Nov 27 13:57:23 2008 Subject: Suggestion: Syntactic sugar for Maps! In-Reply-To: References: Message-ID: <20081127190341.GE23682@scytale.galois.com> circularfunc: > I suggest Haskell introduce some syntactic sugar for Maps. > > Python uses {"this": 2, "is": 1, "a": 1, "Map": 1} > > Clojure also use braces: {:k1 1 :k2 3} where whitespace is comma but > commas are also allowed. > > I find the import Data.Map and then fromList [("hello",1), ("there", > 2)] or the other form that I forgot(because it is to long!) to be to > long... > > So why not {"hello": 1, "there": 2} ? > Well, one problem is that we don't have a definitive Map library. Which kind of Map would you like? IntMap/Map/AVLTree? Some other tree? That said, you could certainly write a little preprocessor/quasiquoting/template haskell for dictionary literals. -- Don From dons at galois.com Thu Nov 27 14:10:57 2008 From: dons at galois.com (Don Stewart) Date: Thu Nov 27 14:04:33 2008 Subject: Suggestion: Syntactic sugar for Maps! In-Reply-To: <20081127190341.GE23682@scytale.galois.com> References: <20081127190341.GE23682@scytale.galois.com> Message-ID: <20081127191057.GF23682@scytale.galois.com> dons: > circularfunc: > > I suggest Haskell introduce some syntactic sugar for Maps. > > > > Python uses {"this": 2, "is": 1, "a": 1, "Map": 1} > > > > Clojure also use braces: {:k1 1 :k2 3} where whitespace is comma but > > commas are also allowed. > > > > I find the import Data.Map and then fromList [("hello",1), ("there", > > 2)] or the other form that I forgot(because it is to long!) to be to > > long... > > > > So why not {"hello": 1, "there": 2} ? > > > > Well, one problem is that we don't have a definitive Map library. Which > kind of Map would you like? IntMap/Map/AVLTree? Some other tree? > > That said, you could certainly write a little > preprocessor/quasiquoting/template haskell for dictionary literals. > Perhaps overloaded *dictionary* literal syntax? So we could have instance Dictionary Map k instance Dictionary IntMap instance Dictionary HashTable instance Dictionary Trie k etc. That would be pretty awesome.. From lennart at augustsson.net Thu Nov 27 15:42:05 2008 From: lennart at augustsson.net (Lennart Augustsson) Date: Thu Nov 27 15:35:44 2008 Subject: Suggestion: Syntactic sugar for Maps! In-Reply-To: <20081127191057.GF23682@scytale.galois.com> References: <20081127190341.GE23682@scytale.galois.com> <20081127191057.GF23682@scytale.galois.com> Message-ID: If we introduce map syntax it should be overloaded. Just as list syntax should be (and will be once I get some time to do it). -- Lennart On Thu, Nov 27, 2008 at 7:10 PM, Don Stewart wrote: > dons: >> circularfunc: >> > I suggest Haskell introduce some syntactic sugar for Maps. >> > >> > Python uses {"this": 2, "is": 1, "a": 1, "Map": 1} >> > >> > Clojure also use braces: {:k1 1 :k2 3} where whitespace is comma but >> > commas are also allowed. >> > >> > I find the import Data.Map and then fromList [("hello",1), ("there", >> > 2)] or the other form that I forgot(because it is to long!) to be to >> > long... >> > >> > So why not {"hello": 1, "there": 2} ? >> > >> >> Well, one problem is that we don't have a definitive Map library. Which >> kind of Map would you like? IntMap/Map/AVLTree? Some other tree? >> >> That said, you could certainly write a little >> preprocessor/quasiquoting/template haskell for dictionary literals. >> > > > Perhaps overloaded *dictionary* literal syntax? > So we could have > > instance Dictionary Map k > instance Dictionary IntMap > instance Dictionary HashTable > instance Dictionary Trie k > > etc. > > That would be pretty awesome.. > > _______________________________________________ > Haskell-prime mailing list > Haskell-prime@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-prime > From bulat.ziganshin at gmail.com Thu Nov 27 16:08:54 2008 From: bulat.ziganshin at gmail.com (Bulat Ziganshin) Date: Thu Nov 27 16:03:50 2008 Subject: Suggestion: Syntactic sugar for Maps! In-Reply-To: References: Message-ID: <262872015.20081128000854@gmail.com> Hello circ, Thursday, November 27, 2008, 9:59:08 PM, you wrote: > So why not {"hello": 1, "there": 2} ? mymap "hello:1 there:2" where mymap implementation is left to the reader :) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com From tatd2 at kent.ac.uk Thu Nov 27 16:14:43 2008 From: tatd2 at kent.ac.uk (Thomas Davie) Date: Thu Nov 27 16:08:27 2008 Subject: Suggestion: Syntactic sugar for Maps! In-Reply-To: References: Message-ID: <2FB40353-C1B3-495A-96B5-CF6A8455F81F@kent.ac.uk> On 27 Nov 2008, at 19:59, circ ular wrote: > I suggest Haskell introduce some syntactic sugar for Maps. > > Python uses {"this": 2, "is": 1, "a": 1, "Map": 1} > > Clojure also use braces: {:k1 1 :k2 3} where whitespace is comma but > commas are also allowed. > > I find the import Data.Map and then fromList [("hello",1), ("there", > 2)] or the other form that I forgot(because it is to long!) to be to > long... > > So why not {"hello": 1, "there": 2} ? In a similar vein, I suggest not only to not do this, but also for Haskell' to remove syntactic sugar for lists (but keep it for strings)! I have two (three if you agree with my opinions on other parts of the language) reasons for this: 1) It's a special case, that doesn't gain anything much. [a,b,c,d] is actually only one character shorter and not really any clearer than a:b:c:d:[]. 2) Removing it would clear up the ',' character for use in infix constructors. 3) (requiring you to agree with my opinions about tuples) it would allow for clearing up the tuple type to be replaced with pairs instead. (,) could become a *real* infix data constructor for pairs. This would make us able to recreate "tuples" simply based on a right associative (,) constructor. I realise there is a slight issue with strictness, and (,) introducing more bottoms in a "tuple" than current tuples have, but I'm sure a strict version of the (,) constructor could be created with the same semantics as the current tuple. Just my 2p Thanks Tom Davie From g9ks157k at acme.softbase.org Thu Nov 27 18:51:23 2008 From: g9ks157k at acme.softbase.org (Wolfgang Jeltsch) Date: Thu Nov 27 18:45:05 2008 Subject: Suggestion: Syntactic sugar for Maps! In-Reply-To: <2FB40353-C1B3-495A-96B5-CF6A8455F81F@kent.ac.uk> References: <2FB40353-C1B3-495A-96B5-CF6A8455F81F@kent.ac.uk> Message-ID: <200811280051.23962.g9ks157k@acme.softbase.org> Am Donnerstag, 27. November 2008 22:14 schrieb Thomas Davie: > On 27 Nov 2008, at 19:59, circ ular wrote: > > I suggest Haskell introduce some syntactic sugar for Maps. > > > > Python uses {"this": 2, "is": 1, "a": 1, "Map": 1} > > > > Clojure also use braces: {:k1 1 :k2 3} where whitespace is comma but > > commas are also allowed. > > > > I find the import Data.Map and then fromList [("hello",1), ("there", > > 2)] or the other form that I forgot(because it is to long!) to be to > > long... > > > > So why not {"hello": 1, "there": 2} ? > > In a similar vein, I suggest not only to not do this, but also for > Haskell' to remove syntactic sugar for lists (but keep it for strings)! > > I have two (three if you agree with my opinions on other parts of the > language) reasons for this: > 1) It's a special case, that doesn't gain anything much. [a,b,c,d] is > actually only one character shorter and not really any clearer than > a:b:c:d:[]. > 2) Removing it would clear up the ',' character for use in infix > constructors. > 3) (requiring you to agree with my opinions about tuples) it would > allow for clearing up the tuple type to be replaced with pairs > instead. (,) could become a *real* infix data constructor for pairs. > This would make us able to recreate "tuples" simply based on a right > associative (,) constructor. I realise there is a slight issue with > strictness, and (,) introducing more bottoms in a "tuple" than current > tuples have, but I'm sure a strict version of the (,) constructor > could be created with the same semantics as the current tuple. > > Just my 2p > > Thanks > > Tom Davie I support this view. Best wishes, Wolfgang From isaacdupree at charter.net Thu Nov 27 18:53:51 2008 From: isaacdupree at charter.net (Isaac Dupree) Date: Thu Nov 27 18:47:32 2008 Subject: .. Add simonpj's ImportShadowing proposal In-Reply-To: <20081121084723.GA10580@haskell.galois.com> References: <20081121084723.GA10580@haskell.galois.com> Message-ID: <492F330F.5050805@charter.net> http://hackage.haskell.org/trac/haskell-prime/wiki/ImportShadowing I agree. It is very tiresome and confusing, because when you say, in your module "M", "M.nub", M doesn't necessarily even export nub, nor did you "import M as M", so it's an odd sort of self-reference. Also that self-reference is banned in some places (maybe, left-hand-sides of definitions?) and required in others (when used when also imported). The "required" part would be mitigated by the proposal. It's probably somewhat more worth warning about when the import was explicit as well as unqualified, e.g. import Data.List (nub) than from merely import Data.List But it's a little confusing, because you can define methods in instances (e.g. Category's id and (.)), but I don't think instance definitions would be affected by the proposal -- only class definitions would. -Isaac From isaacdupree at charter.net Thu Nov 27 19:17:15 2008 From: isaacdupree at charter.net (Isaac Dupree) Date: Thu Nov 27 19:11:02 2008 Subject: Suggestion: Syntactic sugar for Maps! In-Reply-To: <2FB40353-C1B3-495A-96B5-CF6A8455F81F@kent.ac.uk> References: <2FB40353-C1B3-495A-96B5-CF6A8455F81F@kent.ac.uk> Message-ID: <492F388B.9000402@charter.net> Thomas Davie wrote: > > On 27 Nov 2008, at 19:59, circ ular wrote: > >> I suggest Haskell introduce some syntactic sugar for Maps. >> >> Python uses {"this": 2, "is": 1, "a": 1, "Map": 1} >> >> Clojure also use braces: {:k1 1 :k2 3} where whitespace is comma but >> commas are also allowed. >> >> I find the import Data.Map and then fromList [("hello",1), ("there", >> 2)] or the other form that I forgot(because it is to long!) to be to >> long... >> >> So why not {"hello": 1, "there": 2} ? let's look at your argument. I'll ignore spaces in character counts because they're all optional here. fromList [("hello", 1), ("there", 2)] { "hello": 1 , "there": 2 } Basically there are two overhead: - "fromList", or "Data.Map.fromList". I'll get back to this later. - that the pair-tuple constructor uses three characters "(", ",", ")" rather than Python's one ":". The latter is easy to fix! ":" already means something in Haskell, so we'll have to pick something else. a & b = (a, b) fromList ["hello" & 1, "there" & 2] or we could start to get creative, for aesthetic purposes... ["hello"? 1, ], or ["hello":-1, ] to define new data (or type synonym?) ":-". Now comes "fromList" and the issue of monomorphism of normal lists. Well, you're going to have to (or want to) specify the type you want at some point, perhaps. The name of the function could be less ugly than "fromList". If you expect pattern-matching, there's another can of worms, and I suggest looking into GHC's new lightweight "view patterns" (I wonder if they can really do this well, though? -- because fromList/toList sorts.) http://www.haskell.org/ghc/docs/6.10.1/html/users_guide/syntax-extns.html#view-patterns > In a similar vein, I suggest not only to not do this, but also for > Haskell' to remove syntactic sugar for lists (but keep it for strings)! not too hard to cope with, though ugly IMHO if we translate it the obvious way: fromList ("hello" & 1 : "there" & 2 : []) > [...] > 3) (requiring you to agree with my opinions about tuples) it would allow > for clearing up the tuple type to be replaced with pairs instead. (,) > could become a *real* infix data constructor for pairs. This would make > us able to recreate "tuples" simply based on a right associative (,) > constructor. I realise there is a slight issue with strictness, and (,) > introducing more bottoms in a "tuple" than current tuples have, but I'm > sure a strict version of the (,) constructor could be created with the > same semantics as the current tuple. you are right, if you follow a simple asymmetric restriction (which, alas, keeps you from using them as ordinary pairs) : data Tup a b = Tup a !b type Tup0 = () type Tup1 a = Tup a () type Tup2 a b = Tup a (Tup b ()) type Tup3 a b c = Tup a (Tup b (Tup c ())) --or, infixr 5 Tup type Tup2 a b = a `Tup` b `Tup` () --etc. -Isaac From john at repetae.net Thu Nov 27 19:20:53 2008 From: john at repetae.net (John Meacham) Date: Thu Nov 27 19:14:31 2008 Subject: Suggestion: Syntactic sugar for Maps! In-Reply-To: References: Message-ID: <20081128002053.GA25367@sliver.repetae.net> On Thu, Nov 27, 2008 at 07:59:08PM +0100, circ ular wrote: > I suggest Haskell introduce some syntactic sugar for Maps. > > Python uses {"this": 2, "is": 1, "a": 1, "Map": 1} > > Clojure also use braces: {:k1 1 :k2 3} where whitespace is comma but > commas are also allowed. > > I find the import Data.Map and then fromList [("hello",1), ("there", > 2)] or the other form that I forgot(because it is to long!) to be to > long... > > So why not {"hello": 1, "there": 2} ? it is hard to see much benefit over something like this: x ==> y = (x,y) myMap = fromList [ "hello" ==> 1, "there" ==> 2 ] John -- John Meacham - ?repetae.net?john?