Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Re: Can fields in a record be optional? (Yitzchak Gale) 2. Re: cabal install reactive-banana-wx (Heinrich Apfelmus) 3. Re: Can fields in a record be optional? (David Virebayre) 4. Re: Can fields in a record be optional? (Yitzchak Gale) 5. Re: Can fields in a record be optional? (Yitzchak Gale) 6. Impossible lib definition? (Obscaenvs 74) 7. about parser question < Programming in haskell _ chapter 8 > ( anyzhen ) ---------------------------------------------------------------------- Message: 1 Date: Mon, 18 Jul 2011 09:57:34 +0300 From: Yitzchak Gale <g...@sefer.org> Subject: Re: [Haskell-beginners] Can fields in a record be optional? To: David Virebayre <dav.vire+hask...@gmail.com> Cc: "beginners@haskell.org" <beginners@haskell.org> Message-ID: <CAOrUaLa-_GvK58Jw8HjRt6izkg7y400emnZO5bpSf7tcHoD=e...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Roger L. Costello wrote: >> data Contract = >> Contract { >> currency :: Currency >> , payments :: Double >> , contracts :: [Contract] >> } >> deriving (Show) David Virebayre wrote: > I'm not sure I would model your datatype this way, I don't like the > idea to put unnecessary undefined values in the case of subcontracts. > > data Contract = Contract ?{ currency :: Currency, payments :: Double } > ? ? ? ? ? ? ?| SubContract { contracts :: [Contract] } I think Roger's original design is just fine. There is nothing "undefined" about the empty list. Roger is saying that every contract has a list of subcontracts. Lists can be empty, and that is legitimate. In effect, Roger has defined his collection of contracts to be a rose tree, and this is the classic way to do that in Haskell. Another option would be to be more explicit about that and use Data.Tree from the containers[1] package, which is included in the Haskell Platform. Tree algorithms are often quite elegant. We haven't seen the rest of Roger's program, but I'll bet it looks really nice with his original definition. Regards, Yitz ------------------------------ Message: 2 Date: Mon, 18 Jul 2011 09:08:07 +0200 From: Heinrich Apfelmus <apfel...@quantentunnel.de> Subject: Re: [Haskell-beginners] cabal install reactive-banana-wx To: beginners@haskell.org Message-ID: <j00m4o$ui8$1...@dough.gmane.org> Content-Type: text/plain; charset=UTF-8; format=flowed Stephen Tetley wrote: > Try installing either installing wxDirect 0.12.1.4; or wxDirect > 012.1.3 with the build option "splitBase" first. > > There's a difference in the cabal files between 0.12.1.3 and 0.12.1.4 > where the file defaults to container Base 3.0 and Containers 0.3 > (wxDirect 0.12.1.3) or Base 4.0 and Containers 0.4 (wxDirect > 0.12.1.4). > > Latest GHC versions have Base 4.0 and Containers 0.4, wxDirect > 0.12.1.4 should work by default for latest GHC versions. wxDirect > 0.12.1.3 needs building with the "splitBase" flag passed to work with > latest GHCs. Use cabal update to fetch the latest package definitions. Since wxdirect only contains an executable, I think you can also do cabal install wxdirect-0.12.1.4 before installing reactive-banana-wx . Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com ------------------------------ Message: 3 Date: Mon, 18 Jul 2011 09:15:45 +0200 From: David Virebayre <dav.vire+hask...@gmail.com> Subject: Re: [Haskell-beginners] Can fields in a record be optional? To: g...@sefer.org Cc: "beginners@haskell.org" <beginners@haskell.org> Message-ID: <cam_wfvvakqxgnbu4yvt03euthhdkg0xabjsc9jf4g4xg1yx...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 2011/7/18 Yitzchak Gale <g...@sefer.org>: > Roger L. Costello wrote: >>> data Contract = >>> ? Contract { >>> ? ? ? ? ? ? ?currency ?:: Currency >>> ? ? ? ? ? ?, payments ?:: Double >>> ? ? ? ? ? ?, contracts :: [Contract] >>> ? ? ? ? ? ?} >>> ?deriving (Show) > > David Virebayre wrote: >> I'm not sure I would model your datatype this way, I don't like the >> idea to put unnecessary undefined values in the case of subcontracts. >> >> data Contract = Contract ?{ currency :: Currency, payments :: Double } >> ? ? ? ? ? ? ?| SubContract { contracts :: [Contract] } > > I think Roger's original design is just fine. > > There is nothing "undefined" about the empty list. Roger is > saying that every contract has a list of subcontracts. Lists can > be empty, and that is legitimate. I'm not sure you read his post entirely. Here's his and function : > (and) c1 c2 = Contract { currency = undefined, payments = undefined, > contracts = [c1, c2] } Notice how he's setting currency and payments to undefined, since he needs only the contracts field for subcontracts. David. ------------------------------ Message: 4 Date: Mon, 18 Jul 2011 10:25:42 +0300 From: Yitzchak Gale <g...@sefer.org> Subject: Re: [Haskell-beginners] Can fields in a record be optional? To: David Virebayre <dav.vire+hask...@gmail.com> Cc: "beginners@haskell.org" <beginners@haskell.org> Message-ID: <CAOrUaLYbBRfDoNap4EyqPOfR2eC8H6MW=niLDXVvbAV=xxs...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 David Virebayre wrote: > I'm not sure you read his post entirely. > > Here's his and function : >> (and) c1 c2 ?= ?Contract { currency = undefined, payments = undefined, >> contracts = [c1, c2] } > > Notice how he's setting currency and payments to undefined, since he > needs only the contracts field for subcontracts. Ah, right, I didn't notice that. Not a good idea. Your design is better then. Another possibility would be Maybe Currency and Maybe Double. That often comes out simpler - but not always. If the case with Currency and Payments is a totally separate case than when there are subcontracts, with different logic, then David's design is best. If the cases are usually handled pretty much in the same way with special handling for when one or more fields is missing, then Maybe is best. -Yitz ------------------------------ Message: 5 Date: Mon, 18 Jul 2011 10:54:28 +0300 From: Yitzchak Gale <g...@sefer.org> Subject: Re: [Haskell-beginners] Can fields in a record be optional? To: Michael Snoyman <mich...@snoyman.com> Cc: "beginners@haskell.org" <beginners@haskell.org> Message-ID: <CAOrUaLZLjragLEmUokup6KLpogoBFJeuPWxaN7TbbEQFW=3...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 I wrote: >> You don't need the added complexity of a type class for >> this - just define the default value. Michael Snoyman wrote: > I don't think it's a case of necessity. It just happens to be very > convenient to be able to use the three letters "def" instead of > "defaultFrobnicatorSettings" or something like that. You can use whatever name you'd like for a default value, short or descriptive. Type classes are a beautiful and powerful technique in Haskell, but they do add some underlying complexity to your types. In my experience, when building and maintaining large code bases in Haskell, things are much easier when you limit the use of type classes to when they are really needed. I create type classes when I need non-trivial polymorphism. Even then, I often prefer simpler techniques such as data types with parameters or passing functions as parameters. There are also advanced techniques using type classes which are needed for building some kinds of libraries. In particular, I have come to the conclusion that type classes are not a good tool for simple namespace control in a typical Haskell program. It is a common mistake for beginners who come to Haskell with a background in OOP to massively overuse type classes. Style is a matter of taste, of course. But much of the power and beauty of Haskell lies away from type classes, and it's a shame to miss out on it. So I think it is important for beginners, especially when coming from OOP, to start out by avoiding defining type classes whenever there is a good alternative (i.e. almost always). Regards, Yitz ------------------------------ Message: 6 Date: Mon, 18 Jul 2011 10:27:39 +0200 From: Obscaenvs 74 <obscae...@gmail.com> Subject: [Haskell-beginners] Impossible lib definition? To: beginners@haskell.org Message-ID: <ca+jttenmcmwudjxmoqavmvgmcmttarxpdezcjrihdy-1t5x...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 >From the source of the package Text.ParserCombinators.ReadP, available at http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/Text-ParserCombinators-ReadP.html#many : many :: ReadP a -> ReadP [a] -- ^ Parses zero or more occurrences of the given parser. many p = return [] +++ many1 p many1 :: ReadP a -> ReadP [a] -- ^ Parses one or more occurrences of the given parser. many1 p = liftM2 (:) p (many p) So `many` is defined in terms of `many1` and vice versa - completely understandable, but here the argument (`p`) does not change. This is above me right now. Anyone care to explain? I'd be grateful. Not that I have to understand it, but it keeps pestering me during my lonely hours. /Fredrik ------------------------------ Message: 7 Date: Mon, 18 Jul 2011 17:20:28 +0800 From: " anyzhen " <jiangzhe...@qq.com> Subject: [Haskell-beginners] about parser question < Programming in haskell _ chapter 8 > To: " Beginners " <Beginners@haskell.org> Message-ID: <tencent_531cb7c84b1631106b874...@qq.com> Content-Type: text/plain; charset="iso-8859-1" well,i am reading the book :<Programming in haskell > chapter 8 functional parsers this chapter try teaching an parser technology,but i have some problem about do keyword --some brief info of types : type Parser a = String -> [(a,String)] item :: Parser Char --item "abc" = [('a',"bc")] return' :: a -> Parser a --return' 'a' "foo" = [('a',"foo")] --below code complier notice... sorry format p2 :: Parser (Char,Char) p2 = do x <- item item y <- item return' (x,y) "No instance for (Monad ((-)) String)) arising from a execute statement Possible fix : add an instance declaration for (Monad ((-)) String)) In a stmt of a 'do' expression : y <- item In the expression: do { x <- item; item; y <- item; return' (x,y)} In an equation for 'p2': p2 = do { x <- item; item; y <- item; ....}" thanks for any help jiangzhen <mail:jiangzhe...@qq.com> -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20110718/c33dde23/attachment.htm> ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 37, Issue 32 *****************************************