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: Are tuples really needed? (Carlos J. G. Duarte) 2. Re: associative arrays (Karl Voelker) 3. Re: Are tuples really needed? (Dmitry Vyal) 4. Re: associative arrays (Dmitry Vyal) 5. complex typeclass/constraint question (Dennis Raddle) ---------------------------------------------------------------------- Message: 1 Date: Tue, 28 Aug 2012 23:07:34 +0100 From: "Carlos J. G. Duarte" <carlos.j.g.dua...@gmail.com> Subject: Re: [Haskell-beginners] Are tuples really needed? To: beginners@haskell.org Message-ID: <503d4126....@gmail.com> Content-Type: text/plain; charset="us-ascii" An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20120828/c44b6c18/attachment-0001.htm> ------------------------------ Message: 2 Date: Tue, 28 Aug 2012 23:19:20 -0700 From: Karl Voelker <ktvoel...@gmail.com> Subject: Re: [Haskell-beginners] associative arrays To: beginners@haskell.org Message-ID: <caffow0z52uynu92pn4+vruvycqbxcp1churhduchvkj32by...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 On Sat, Aug 25, 2012 at 8:11 AM, Nick Vanderweit <nick.vanderw...@gmail.com> wrote: > I'd still recommend Data.Map, since it's a much more efficient data structure > for the task. Data.Map.lookup has better asymptotic time complexity than Prelude.lookup, but the relevant measures of efficiency depend on the situation. -Karl ------------------------------ Message: 3 Date: Wed, 29 Aug 2012 10:21:16 +0400 From: Dmitry Vyal <akam...@gmail.com> Subject: Re: [Haskell-beginners] Are tuples really needed? To: "Carlos J. G. Duarte" <carlos.j.g.dua...@gmail.com> Cc: beginners@haskell.org Message-ID: <503db4dc.2070...@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed > Wouldn't Haskell be "cleaner" if it had left tuples out, replacing them with some standard types added (Pair, Triple, ...) and similar fst, snd functions? Then curry and uncurry wouldn't even be needed if I have this right. I guess it's a matter of syntax. Arguably (x,y) is much clearer and closer to mathematical notation than Pair x y. Don't forget, the same story for lists, you can represent [a,b,c] with Cons a (Cons b (Cons c Nil)) but from ancient times of lispers use a syntactic sugar for that. ------------------------------ Message: 4 Date: Wed, 29 Aug 2012 10:25:41 +0400 From: Dmitry Vyal <akam...@gmail.com> Subject: Re: [Haskell-beginners] associative arrays To: Karl Voelker <ktvoel...@gmail.com>, beginners@haskell.org Message-ID: <503db5e5.2010...@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed On 29.08.2012 10:19, Karl Voelker wrote: > > Data.Map.lookup has better asymptotic time complexity than > Prelude.lookup, but the relevant measures of efficiency depend on the > situation. > Can you please elaborate a bit? I suspect lists better when there are just a few elements, but how much is a "few"? And what's about storage efficiency? How big is (Data.Map.fromList [1])? ------------------------------ Message: 5 Date: Wed, 29 Aug 2012 00:28:37 -0700 From: Dennis Raddle <dennis.rad...@gmail.com> Subject: [Haskell-beginners] complex typeclass/constraint question To: Haskell Beginners <beginners@haskell.org> Message-ID: <CAKxLvor=FUA0LurCPsoXyMPGAA=hwuxr_g4ejubol70ox_t...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" {- I'm writing code to do some combinatorial construction via test-and-evaluate algorithms. And I want to write a very generic algorithm. The idea is that the item being constructed has a current state, which is represented by a data type of typeclass EvalState. And the algorithm will consider a set of new elements to add to the object being constructed, represented by a data type of typeclass ElemSet. Here are the class definitions: -} class ElemSet a where elemSetNumElements :: a -> Int class EvalState s where isCompleteState :: s -> Bool newElemSet :: ElemSet a => s -> a integrateElem :: ElemSet a => a -> Int -> s -> s -- given an elem set, and an index of the elem to choose , compute a score scoreElem :: ElemSet a => a -> Int -> s -> EvalScore type EvalScore = Float type RandomnessChooser = [(EvalScore,Int)] -> ErrorRand Int {- here's my generic search algorithm written using the typeclasses the problem I'm having relates to the fact that I need to call 'integrateElem' which is a function in typeclass EvalState, and one of the arguments has the constraint of being of typeclass ElemSet, but I don't know how to put that constraint in. The specific error is "Ambigous type variable 'a' in the constraint: 'ElemSet a' arising from a use of 'integrateElem'" -} search :: (EvalState s) => RandomnessChooser -> s -> ErrorRand ssearch chooser state = do if isCompleteState state then return state else do let elemSet = newElemSet state n = elemSetNumElements elemSet scores = map g [0..n-1] g i = (scoreElem elemSet i state,i) chosenElemIdx <- chooser scores let newState = integrateElem elemSet chosenElemIdx state search chooser newState -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20120829/f8a2c426/attachment.htm> ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 50, Issue 35 *****************************************