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. Resources for Learning (ranveer raghuwanshi) 2. Snap layouts | app examples (Jakub Oboza) 3. Re: Resources for Learning (Paulo Pocinho) 4. Ord and Eq instances for complex types (Mike Meyer) 5. Re: Resources for Learning (Paulo Pocinho) 6. Re: Ord and Eq instances for complex types (Daniel Fischer) 7. Re: Ord and Eq instances for complex types (Mike Meyer) 8. Re: Ord and Eq instances for complex types (Daniel Fischer) ---------------------------------------------------------------------- Message: 1 Date: Wed, 19 Oct 2011 01:58:45 +0530 From: ranveer raghuwanshi <ranveer.ra...@gmail.com> Subject: [Haskell-beginners] Resources for Learning To: beginners@haskell.org Message-ID: <ca+pxnz9xnp3rthk7ss6juk3euxxla+hhbe2tjauwotfjpi1...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" Can someone direct me to good video tutorial resources related to haskell.? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20111019/05448676/attachment-0001.htm> ------------------------------ Message: 2 Date: Tue, 18 Oct 2011 21:34:47 +0100 From: Jakub Oboza <jakub.ob...@gmail.com> Subject: [Haskell-beginners] Snap layouts | app examples To: Beginners@haskell.org Message-ID: <9c4c4c1c-35a6-4c22-8f43-69ceac2a3...@gmail.com> Content-Type: text/plain; charset=us-ascii Dear Haskellers Can you provide me with example of layout'ing system for snap. I mean something like layouts in "rails" So if you have a standard heist layout for actions like index, show, edit i would like to have a global application layout that will have javascripts/css tags and rest of "action" layouts will be just yield inside of it. I don't know if this description is perfect :D. ps. example of medium size snap applications would also be nice. Kind regards Jakub Oboza ------------------------------ Message: 3 Date: Tue, 18 Oct 2011 21:40:06 +0100 From: Paulo Pocinho <poci...@gmail.com> Subject: Re: [Haskell-beginners] Resources for Learning To: ranveer raghuwanshi <ranveer.ra...@gmail.com> Cc: beginners@haskell.org Message-ID: <cak4i1qqkgbhssejnbbqyey_g6xg3pesxnc3pvltt8axrbqk...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 http://channel9.msdn.com/Tags/haskell On 18 October 2011 21:28, ranveer raghuwanshi <ranveer.ra...@gmail.com> wrote: > Can someone direct me to good video tutorial resources related to haskell.? > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > ------------------------------ Message: 4 Date: Tue, 18 Oct 2011 14:13:03 -0700 From: Mike Meyer <m...@mired.org> Subject: [Haskell-beginners] Ord and Eq instances for complex types To: Beginners@haskell.org Message-ID: <CAD=7u2cxwposnagmdk8efzjv1uvjvy-v2ex2w91ogqxnsno...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" I'm working on a problem dealing with poker hands, and need to rank them. The Ord instance seems like a natural for this, but the code came out with a lot of repetitions in it. To wit, given suitable definitions for Rank, Suit and Card, I define a Hand as: data Hand = HighCard [Card] | PairOf Rank [Card] | TwoPair Rank Rank [Card] | ThreeOfAKind Rank [Card] | Straight [Card] | Flush [Card] | FullHouse Rank Rank [Card] | FourOfAKind Rank [Card] | StraightFlush [Card] deriving (Show) [N.B. - the single or double rank is the Rank of the cards participating in that type of hand, and is compared before the rest of the cards, so AQQJT is not as good a hand as KK321 - a pair of kings beating a pair of queens.] Eq winds up looking like: instance Eq Hand where h1 == h2 = cards h1 == cards h2 where cards (HighCard h) = h cards (PairOf _ h) = h -- etc. and Ord (with appropriate check functions) like: instance Ord Hand where compare (StraightFlush h1) (StraightFlush h2) = compare h1 h2 compare (StraightFlush _) _ = GT compare _ (StraightFlush _) = LT compare (FourOfAKind r1 h1) (FourOfAKind r2 h2)= check r1 h1 r2 h2 compare (FourOfAKind _ _) _ = GT compare _ (FourOfAKind _ _) = LT -- etc Seems like there ought to be an easier way. I can see that making the types of hands an enum (HandType), then defining a hand as a record: data Hand = { type :: HandType, rank1 :: Maybe Rank, -- (2, 3, 4) of a kind rank2 :: Maybe Rank, -- 2 pair, full house cards :: [Card] } would make the comparisons a lot easier. But that would make constructing them a lot more painful. I can't just say "PairOf Ace hand" to mark a hand as a pair of aces. It also the type checking from the constructors. Is there some third alternative I've overlooked that combines the best features of both approaches? Thanks, <mike -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20111018/f6971cde/attachment-0001.htm> ------------------------------ Message: 5 Date: Tue, 18 Oct 2011 22:27:41 +0100 From: Paulo Pocinho <poci...@gmail.com> Subject: Re: [Haskell-beginners] Resources for Learning To: ranveer raghuwanshi <ranveer.ra...@gmail.com> Cc: beginners@haskell.org Message-ID: <CAK4i1qS1Zv04VEaqCC+GU+WxJOdse4Q1dgY=St4OA8LQj=v...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 Hi again. The link I gave has some very interesting lectures on haskell. It is not really for someone beginning to program but I believe imperative programmers can catch up quickly. For real beginners it is best to search haskell.org or read an introductory book such as learnyouahaskell.com On 18 October 2011 21:50, ranveer raghuwanshi <ranveer.ra...@gmail.com> wrote: > Are these basic video tutorials.? > I am completely new to the world of haskell and functional programming. > > On Wed, Oct 19, 2011 at 2:10 AM, Paulo Pocinho <poci...@gmail.com> wrote: >> >> http://channel9.msdn.com/Tags/haskell >> >> On 18 October 2011 21:28, ranveer raghuwanshi <ranveer.ra...@gmail.com> >> wrote: >> > Can someone direct me to good video tutorial resources related to >> > haskell.? >> > _______________________________________________ >> > Beginners mailing list >> > Beginners@haskell.org >> > http://www.haskell.org/mailman/listinfo/beginners >> > >> > > > ------------------------------ Message: 6 Date: Tue, 18 Oct 2011 23:47:18 +0200 From: Daniel Fischer <daniel.is.fisc...@googlemail.com> Subject: Re: [Haskell-beginners] Ord and Eq instances for complex types To: beginners@haskell.org Message-ID: <201110182347.18444.daniel.is.fisc...@googlemail.com> Content-Type: Text/Plain; charset="utf-8" On Tuesday 18 October 2011, 23:13:03, Mike Meyer wrote: > I'm working on a problem dealing with poker hands, and need to rank > them. The Ord instance seems like a natural for this, but the code came > out with a lot of repetitions in it. > > Is there some third alternative I've overlooked that combines the best > features of both approaches? > > Thanks, > <mike Well, you could use record syntax in the Hand type to avoid defining cards in the Eq instance, data Hand = HighCard { cards :: [Card] } | PairOf { rank :: Rank, cards :: [Card } ... | FulHouse { rank, minorRank :: Rank, cards :: [Card] } | FourOfAKind { rank :: Rank, cards :: [Card] } | StraightFlush { cards :: [Card] } deriving Show instance Eq Hand where -- if your hands are well-formed, you h1 == h2 = cards h1 == cards h2 -- could also derive Eq quality :: Hand -> Int quality HighCard{} = 0 quality PairOf{} = 1 ... quality StraightFlush{} = 8 instance Ord Hand where compare h1 h2 = case compare (quality h1) (quality h2) of EQ -> case h1 of StraightFlush c1 -> compare c1 (cards h2) FourOfAKind r1 c1 -> case compare r1 (rank h2) of EQ -> compare c1 (cards h2) other -> other ... other -> other ------------------------------ Message: 7 Date: Tue, 18 Oct 2011 15:27:19 -0700 From: Mike Meyer <m...@mired.org> Subject: Re: [Haskell-beginners] Ord and Eq instances for complex types To: Daniel Fischer <daniel.is.fisc...@googlemail.com> Cc: beginners@haskell.org Message-ID: <CAD=7u2dqni7ydws0_st6afxvc5a6y9gu0omjszxqws+bwrk...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" On Tue, Oct 18, 2011 at 2:47 PM, Daniel Fischer < daniel.is.fisc...@googlemail.com> wrote: > On Tuesday 18 October 2011, 23:13:03, Mike Meyer wrote: > > I'm working on a problem dealing with poker hands, and need to rank > > them. The Ord instance seems like a natural for this, but the code came > > out with a lot of repetitions in it. > > > > > Is there some third alternative I've overlooked that combines the best > > features of both approaches? > > > > Thanks, > > <mike > > Well, you could use record syntax in the Hand type to avoid defining cards > in the Eq instance, > > data Hand > = HighCard { cards :: [Card] } > | PairOf { rank :: Rank, cards :: [Card } > ... > | FulHouse { rank, minorRank :: Rank, cards :: [Card] } > | FourOfAKind { rank :: Rank, cards :: [Card] } > | StraightFlush { cards :: [Card] } > deriving Show > > instance Eq Hand where -- if your hands are well-formed, you > h1 == h2 = cards h1 == cards h2 -- could also derive Eq > I was thinking of some kind of mixed solution over lunch. This looks better than what I had in mind. But what does "well-formed" mean in this context? > quality :: Hand -> Int > quality HighCard{} = 0 > quality PairOf{} = 1 > ... > quality StraightFlush{} = 8 > Could this be replaced by an assoc list of some kind? I was actually contemplating adding a quality field to the record. > instance Ord Hand where > compare h1 h2 = > case compare (quality h1) (quality h2) of > EQ -> case h1 of > StraightFlush c1 -> compare c1 (cards h2) > FourOfAKind r1 c1 -> > case compare r1 (rank h2) of > EQ -> compare c1 (cards h2) > other -> other > ... > other -> other > What I'd really like to do is collapse the three types of comparison (i.e. - hand, rank hand, rank minorrank hand) into one comparison each. Thanks, <mike -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20111018/48350422/attachment-0001.htm> ------------------------------ Message: 8 Date: Wed, 19 Oct 2011 01:01:38 +0200 From: Daniel Fischer <daniel.is.fisc...@googlemail.com> Subject: Re: [Haskell-beginners] Ord and Eq instances for complex types To: Mike Meyer <m...@mired.org> Cc: beginners@haskell.org Message-ID: <201110190101.38126.daniel.is.fisc...@googlemail.com> Content-Type: Text/Plain; charset="utf-8" On Wednesday 19 October 2011, 00:27:19, Mike Meyer wrote: > On Tue, Oct 18, 2011 at 2:47 PM, Daniel Fischer < > > daniel.is.fisc...@googlemail.com> wrote: > > On Tuesday 18 October 2011, 23:13:03, Mike Meyer wrote: > > > I'm working on a problem dealing with poker hands, and need to rank > > > them. The Ord instance seems like a natural for this, but the code > > > came out with a lot of repetitions in it. > > > > > > > > > Is there some third alternative I've overlooked that combines the > > > best features of both approaches? > > > > > > Thanks, > > > <mike > > > > Well, you could use record syntax in the Hand type to avoid defining > > cards in the Eq instance, > > > > data Hand > > > > = HighCard { cards :: [Card] } > > > > | PairOf { rank :: Rank, cards :: [Card } > > > > ... > > > > | FulHouse { rank, minorRank :: Rank, cards :: [Card] } > > | FourOfAKind { rank :: Rank, cards :: [Card] } > > | StraightFlush { cards :: [Card] } > > | > > deriving Show > > > > instance Eq Hand where -- if your hands are well-formed, you > > > > h1 == h2 = cards h1 == cards h2 -- could also derive Eq > > I was thinking of some kind of mixed solution over lunch. This looks > better than what I had in mind. But what does "well-formed" mean in > this context? That the type of hand is properly reflected in the constructor, that the hand actually has the quality stated by the constructor and no better, for example that a full house is never created as a PairOf or ThreeOfAKind (or was it TripleOf?). And that the list of cards is sorted according to some criterion (this is also presumed in the explicit Eq instance). > > > quality :: Hand -> Int > > quality HighCard{} = 0 > > quality PairOf{} = 1 > > ... > > quality StraightFlush{} = 8 > > Could this be replaced by an assoc list of some kind? Sure, but why? Making it an assoc list would not be trivial, if you don't enumerate all possible hands ( ;-), you'd either need a function to create a default hand with the same constructor (so you can use the Eq instance to do the lookup) or some custom lookup function doing basically the same. > > I was actually contemplating adding a quality field to the record. If you don't export the constructors and take care to create only hands with the correct quality, that is possible. I'm not sure if it gains anything, though. > > > instance Ord Hand where > > > > compare h1 h2 = > > > > case compare (quality h1) (quality h2) of > > > > EQ -> case h1 of > > > > StraightFlush c1 -> compare c1 (cards h2) > > FourOfAKind r1 c1 -> > > > > case compare r1 (rank h2) of > > > > EQ -> compare c1 (cards h2) > > other -> other > > > > ... > > > > other -> other > > What I'd really like to do is collapse the three types of comparison > (i.e. - hand, rank hand, rank minorrank hand) into one comparison each. I don't see what you mean, could you elaborate? ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 40, Issue 29 *****************************************