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. Representing a Set using a boolean function (Robert Weisser) 2. Re: Representing a Set using a boolean function (Felipe Almeida Lessa) 3. Re: Representing a Set using a boolean function (Brent Yorgey) 4. Re: basic data types (Peter Hall) 5. Audio packages. (Sourabh) 6. Re: Audio packages. (Henk-Jan van Tuyl) ---------------------------------------------------------------------- Message: 1 Date: Fri, 30 Dec 2011 17:53:26 -0500 From: "Robert Weisser" <robert.weis...@gmx.com> Subject: [Haskell-beginners] Representing a Set using a boolean function To: beginners@haskell.org Message-ID: <20111230225327.5...@gmx.com> Content-Type: text/plain; charset="utf-8" I am working through Thompson's "Haskell The Craft of Functional programming", 2nd edition. I am not doing this as part of a class. It is just for my own enjoyment. I am having a problem with Exercise 16.38. Here is the exercise: The abstract data type Set a can be represented in a number of different ways. Alternatives include arbitrary lists (rather than ordered lists without repetitions) and Boolean valued functions, that is elements of the type a -> Bool. Give implementations of the type using these two representations. ? Note: the book previously showed a representation of Set a using ordered lists without repetitions. I had no problem representing Set a with arbitrary lists. My problem came when I tried to represent Set a with boolean functions. My first question was this: which of the following was Thompson asking for? newtype Set a = Set (a -> Bool) (version 1) ? newtype Set a = Set [a -> Bool] (version 2) I decided on version 1. Version 2 did not seem to have any advantage over version 1. Also, version 1 resembled something earlier in the book (an associative list implemented as a boolean function). I had no trouble with functions in the Module export list (see code below) which did not need to know the contents of the set. However, when I got to eqSet, I was stumped. I don't see how any function can see inside the set. I don't know enough Haskell to be certain, but it looks impossible to me. Is there something I am missing? ? > module Set ( > Set, > empty, -- Set a > sing, -- a -> Set a > memSet, -- Ord a => Set a -> a -> Bool > union, -- Ord a => Set a -> Set a -> Set a > inter, -- Ord a => Set a -> Set a -> Set a > diff, -- Ord a => Set a -> Set a -> Set a > symmDiff, -- Ord a => Set a -> Set a -> Set a > eqSet, -- Eq a => Set a -> Set a -> Bool > subSet, -- Ord a => Set a -> Set a -> Bool > makeSet, -- Ord a => [a] -> Set a > mapSet, -- Ord b => (a -> b) -> Set a -> Set b > filterSet, -- (a -> Bool) -> Set a -> Set a > foldSet, -- (a -> a -> a) -> a -> Set a -> a > showSet, -- (a -> String) -> Set a -> String > card) -- Set a -> Int > where > > import Data.List hiding (union) > > instance Eq a => Eq (Set a) where > (==) = eqSet > > instance Ord a => Ord (Set a) where > (<=) = leqSet > > newtype Set a = Set (a -> Bool) > > empty :: Set a > empty = Set $ \_ -> False > > sing :: Ord a => a -> Set a > sing y = Set $ \x -> x == y > > memSet :: Ord a => Set a -> a -> Bool > memSet (Set f) x = f x > > union :: Ord a => Set a -> Set a -> Set a > union s1 s2 = Set $ \x -> memSet s1 x || memSet s2 x > > inter :: Ord a => Set a -> Set a -> Set a > inter s1 s2 = Set $ \x -> memSet s1 x && memSet s2 x > > diff :: Ord a => Set a -> Set a -> Set a > diff s1 s2 = Set $ \x -> memSet s1 x && not (memSet s2 x) > > symmDiff :: Ord a => Set a -> Set a -> Set a > symmDiff s1 s2 = union (diff s1 s2) (diff s2 s1) > > -- Not exported: > contents :: Ord a => Set a -> [a] > contents (Set f) = undefined > > eqSet :: Eq a => Set a -> Set a -> Bool > eqSet (Set xs) (Set ys) = undefined > > -- Not exported: > leqSet :: Ord a => Set a -> Set a -> Bool > leqSet (Set xs) (Set ys) = undefined > > subSet :: Ord a => Set a -> Set a -> Bool > subSet (Set xs) (Set ys) = undefined > > makeSet :: Ord a => [a] -> Set a > makeSet xs = foldl addElem empty xs > > -- Not exported: > addElem :: Ord a => Set a -> a -> Set a > addElem (Set f) y = Set g > where > g x = if x == y then True > else f x > > mapSet :: Ord b => (a -> b) -> Set a -> Set b > mapSet f (Set xs) = undefined > > filterSet :: (a -> Bool) -> Set a -> Set a > filterSet p (Set xs) = undefined > > foldSet :: (a -> a -> a) -> a -> Set a -> a > foldSet f x (Set xs) = undefined > > showSet :: (a -> String) -> Set a -> String > showSet f (Set xs) = undefined > > card :: Set a -> Int > card (Set xs) = undefined For testing, I used the following. I checked individual values for membership in the union, intersection, etc. > list1 = [1..4] :: [Int] > list2 = [3..6] :: [Int] > > set1 = makeSet list1 > set2 = makeSet list2 > > setUnion = union set1 set2 > setInter = inter set1 set2 > setDiff = diff set1 set2 > setSymmDiff = symmDiff set1 set2 ? ? Robert Weisser ? ------------------------------ Message: 2 Date: Fri, 30 Dec 2011 21:02:34 -0200 From: Felipe Almeida Lessa <felipe.le...@gmail.com> Subject: Re: [Haskell-beginners] Representing a Set using a boolean function To: Robert Weisser <robert.weis...@gmx.com> Cc: beginners@haskell.org Message-ID: <CANd=OGEMzQuDMW5_o77wP0QCP=NPp=yp73fBxYzKMTP=5rt...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 On Fri, Dec 30, 2011 at 8:53 PM, Robert Weisser <robert.weis...@gmx.com> wrote: > ?newtype Set a = Set (a -> Bool) (version 1) This one, certainly. > However, when I got to eqSet, I was > ?stumped. I don't see how any function can see inside the set. I don't know > ?enough Haskell to be certain, but it looks impossible to me. Is there > ?something I am missing? You really can't look inside the function to decide if they are equal. The only way of doing it would be enumerating all possible items that could be in a set and checking them. Something like eqSet s1 s2 = and [memSet s1 x == memSet s2 x | x <- allValues] class AllValues a where allValues :: [a] instance AllValues Bool where allValues = [True, False] instance AllValues Char where allValues = ['\0'..] instance AllValues Int where allValues = [0..] ++ [-1,-2..] and so on. Note that usually this is a really bad idea and perhaps it would be better to not implement eqSet at all. HTH, -- Felipe. ------------------------------ Message: 3 Date: Fri, 30 Dec 2011 21:23:14 -0500 From: Brent Yorgey <byor...@seas.upenn.edu> Subject: Re: [Haskell-beginners] Representing a Set using a boolean function To: beginners@haskell.org Message-ID: <20111231022314.ga21...@seas.upenn.edu> Content-Type: text/plain; charset=us-ascii On Fri, Dec 30, 2011 at 05:53:26PM -0500, Robert Weisser wrote: > stumped. I don't see how any function can see inside the set. I don't know > enough Haskell to be certain, but it looks impossible to me. Is there > something I am missing? Nope, you're absolutely right. This is one of the big differences between an "intensional" representation of a set (such as a list) which lets you inspect the set's internal structure, and an "extensional" representation (like a -> Bool) which only lets you inspect the set's "behavior". You may enjoy trying to think of other differences (hint: think about efficiency). -Brent ------------------------------ Message: 4 Date: Sat, 31 Dec 2011 03:55:00 +0000 From: Peter Hall <peter.h...@memorphic.com> Subject: Re: [Haskell-beginners] basic data types To: Stanis?aw Findeisen <stf-l...@eisenbits.com> Cc: beginners@haskell.org Message-ID: <CAA6hAk6t63LVgNHqza1RLnaSQde9C6G+0VraCN0iY=o3v3t...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 A reasonable analogy (though it's not nearly the same thing) for Haskell classes is Java interfaces. e.g. in Java, Boolean is a class that implements Serializable and Comparable, while Haskell's Bool type is an instance of all those classes you listed. In Haskell, the equivalent of Java's 'class Boolean implements Comparable<Boolean> ...' is 'instance Eq Bool where ... '. In Java you declare the interfaces that a class implements when the class is declared. In Haskell, you can add class instances to any type later, not just in the module that declared the type. Peter 2011/12/30 Stanis?aw Findeisen <stf-l...@eisenbits.com>: > Hi > > What are those basic data type instances? For example here: > http://www.haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Bool > we have: > > Instances > > Bounded Bool > Enum Bool > Eq Bool > Data Bool > Ord Bool > Read Bool > Show Bool > Ix Bool > Typeable Bool > Generic Bool > Storable Bool > > What is the difference between, e.g., Bounded Bool and Enum Bool? > > -- > This e-mail address is invalid, see: > http://people.eisenbits.com/~stf/public-email-note.html . > > OpenPGP: E3D9 C030 88F5 D254 434C ?6683 17DD 22A0 8A3B 5CC0 > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners ------------------------------ Message: 5 Date: Sat, 31 Dec 2011 00:15:54 -0800 From: Sourabh <sourabh.s.jo...@gmail.com> Subject: [Haskell-beginners] Audio packages. To: beginners@haskell.org Message-ID: <CAK0HM3=WU3s6FTPhhA87JycB9y+=ypnwduxa-jxmkcgkflm...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" Hello, I'm a Haskell beginner and am working on my first *serious* haskell project. After going through a few books, and working on the exercises in the books, I finally started writing a small 2D game in Haskell. I figured this would give me lots of exposure to Haskell, and also on how graphics, keyboard, sound, etc are done. Also, I'm working on windows, so unfortunately building the correct libraries has been a bit of a pain. In fact, my question pertains to this. I am currently at the stage where I can get various events to happen correctly in the game, but there is no sound. I started looking at various audio related packages earlier today, but I can't seem to find any documentation on any packages. To add to my woes, I just can't, for the life of me, get any packages to install correctly on windows. So far I have tried OpenAL, SDL-mixer, PortAudio on windows, and none of them seem to work. Cabal install outright fails and asks me to go the MinGW/msys route. When I try to go through this route (which worked successfully for me for graphics), I still can't get any libraries to build. The various errors I have encountered range from configure/build failing, to dependencies not installing correctly. Looking at the various hits on google, it seems that I am not alone in this. I finally managed to get SDL to install (but not SDL-mixer). Even though SDL has an Audio component to it, the lack of documentation on the API has left me with no way to figure out how to actually use this...? Link that worked for me: http://www.animal-machine.com/blog/2010/04/a-haskell-adventure-in-windows/ Finally, I have started getting this error every time I do a cabal install now: Setup.hs:1:8: Could not find module `Distribution.Simple': Use -v to see a list of the files searched for. Have I finally done something terrific and blown everything apart? Sadly, instead of spending time writing Haskell code, I find myself spending a lot of time getting libraries to install and work on Windows. Is this common, or am I doing something wrong? At this point I would very much like advice on a couple of things: 1. Does anyone know any good Audio packages, that would work on windows, along with some examples and documentation of the API? 2. What should I do to get cabal to start installing stuff again? I apologize if I sound a bit frustrated, because I guess I am. :) Thanks for any advice, and have a happy new year! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20111231/a6ed53a6/attachment-0001.htm> ------------------------------ Message: 6 Date: Sat, 31 Dec 2011 11:10:15 +0100 From: "Henk-Jan van Tuyl" <hjgt...@chello.nl> Subject: Re: [Haskell-beginners] Audio packages. To: beginners@haskell.org, Sourabh <sourabh.s.jo...@gmail.com> Message-ID: <op.v7cmjdpppz0...@zen5.arnhem.chello.nl> Content-Type: text/plain; charset=iso-8859-15; format=flowed; delsp=yes On Sat, 31 Dec 2011 09:15:54 +0100, Sourabh <sourabh.s.jo...@gmail.com> wrote: : : > At this point I would very much like advice on a couple of things: > 1. Does anyone know any good Audio packages, that would work on windows, > along with some examples and documentation of the API? I use wxHaskell for game development, it has functions built-in to play sound files. Regards, Henk-Jan van Tuyl -- http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming -- ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 42, Issue 35 *****************************************