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. IO Question (Nathan Holden) 2. Re: IO Question (Alexander Dunlap) 3. about the concatenation on a tree (Max cs) 4. Re: about the concatenation on a tree (Thomas Davie) 5. bottom case in proof by induction (ra...@msn.com) 6. Re: about the concatenation on a tree (Thomas Davie) 7. until and Time (Steve Klabnik) ---------------------------------------------------------------------- Message: 1 Date: Tue, 30 Dec 2008 22:41:02 -0500 From: "Nathan Holden" <nathanmhol...@gmail.com> Subject: [Haskell-beginners] IO Question To: beginners@haskell.org Message-ID: <305228b20812301941t781efe6ajf51e644de1255...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" I've been playing around with some types, and such, and I can get some basic IO. But the thing that confused me is this: How is it that IO [Char] == [Char] can be True, but IO a == a is a type error? How can you implement eq for a type so that IO (type) == type? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20081230/338c9178/attachment-0001.htm ------------------------------ Message: 2 Date: Tue, 30 Dec 2008 20:36:22 -0800 From: "Alexander Dunlap" <alexander.dun...@gmail.com> Subject: Re: [Haskell-beginners] IO Question To: "Nathan Holden" <nathanmhol...@gmail.com> Cc: beginners@haskell.org Message-ID: <57526e770812302036x573c6ebam11b0c6c1d8aa5...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 On Tue, Dec 30, 2008 at 7:41 PM, Nathan Holden <nathanmhol...@gmail.com> wrote: > I've been playing around with some types, and such, and I can get some basic > IO. But the thing that confused me is this: How is it that IO [Char] == > [Char] can be True, but IO a == a is a type error? How can you implement eq > for a type so that IO (type) == type? The Eq type class is essentially defined as such: class Eq a where (==) :: a -> a -> Bool I don't know how you are even calling (==) on objects of type IO [Char] and [Char], since the type signature of (==) says that both of its arguments have to have the same type. Could you give more details of what is going on? Alex ------------------------------ Message: 3 Date: Wed, 31 Dec 2008 15:02:48 +0000 From: "Max cs" <max.cs.2...@googlemail.com> Subject: [Haskell-beginners] about the concatenation on a tree To: beginners@haskell.org, haskell-c...@haskell.org Message-ID: <902ff3e80812310702y7b2e4c28g356baffbb8df...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" hi all, not sure if there is someone still working during holiday like me : ) I got a little problem in implementing some operations on tree. suppose we have a tree date type defined: data Tree a = Leaf a | Branch (Tree a) (Tree a) I want to do a concatenation on these tree just like the concat on list. Anyone has idea on it? or there are some existing implementation? Thank you and Happy New Year! regards, Max -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20081231/20794b50/attachment-0001.htm ------------------------------ Message: 4 Date: Wed, 31 Dec 2008 17:30:30 +0100 From: Thomas Davie <tom.da...@gmail.com> Subject: Re: [Haskell-beginners] about the concatenation on a tree To: "Max cs" <max.cs.2...@googlemail.com> Cc: beginners@haskell.org, haskell-c...@haskell.org Message-ID: <a16f5975-3bfb-466e-ba4b-0966c36ff...@gmail.com> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes On 31 Dec 2008, at 16:02, Max cs wrote: > hi all, not sure if there is someone still working during holiday > like me : ) > > I got a little problem in implementing some operations on tree. > > suppose we have a tree date type defined: > > data Tree a = Leaf a | Branch (Tree a) (Tree a) > > I want to do a concatenation on these tree just like the concat on > list. > Anyone has idea on it? or there are some existing implementation? > > Thank you and Happy New Year! > How would you like to concatenate them? Concatonation on lists is easy because there's only one end point to attach the next list to, on a tree though, there are many leaves to attach things to. Here's a few examples though: Attaching to the right most point on the tree (tree data structure modified to store data in branches not leaves here) data Tree a = Leaf | Branch (Tree a) a (Tree a) concatT :: [Tree a] -> Tree a concatT = foldr1 appendT appendT :: Tree a -> Tree a -> Tree a appendT Leaf t = t appendT (Branch l x r) t = Branch l x (appendT r t) Attaching to *all* the leaves on the tree (same modification to the data structure) concatT :: [Tree a] -> Tree a concatT = foldr1 appendT appendT :: Tree a -> Tree a -> Tree a appendT Leaf t = t appendT (Branch l x r) t = Branch (appendT l t) x (appendT r t) merging a list of trees maintaining them as ordered binary trees concatT :: Ord a => [Tree a] -> Tree a concatT = foldr1 unionT unionT :: Ord a => Tree a -> Tree a -> Tree a unionT t = foldrT insertT t foldrT :: (a -> b -> b) -> b -> Tree a -> b foldrT f z Leaf = z foldrT f z (Branch l x r) = f x (foldrT f (foldrT f z r) l) insertT :: Ord a => a -> Tree a -> Tree a insertT x Leaf = Branch Leaf x Leaf insertT x (Branch l y r) | x <= y = Branch (insertT x l) y r | otherwise = Branch l y (insertT x r) Hope that helps. Bob ------------------------------ Message: 5 Date: Wed, 31 Dec 2008 21:58:48 -0000 From: <ra...@msn.com> Subject: [Haskell-beginners] bottom case in proof by induction To: <haskell-c...@haskell.org>, <beginners@haskell.org> Message-ID: <bay113-ds6b6f52b95e41cd6f55a07bb...@phx.gbl> Content-Type: text/plain; charset="gb2312" Dear all, Happy New Year! I am learning the Induction Proof over Haskell, I saw some proofs for the equivalence of two functions will have a case called 'bottom' but some of them do no have. What kind of situation we should also include the bottom case to the proof? How about the functions do not have the 'bottom' input such as: foo [] = [] foo (x:xs) = x : (foo xs) thank you, Raeck -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20081231/8c98ba3c/attachment-0001.htm ------------------------------ Message: 6 Date: Wed, 31 Dec 2008 23:05:45 +0100 From: Thomas Davie <tom.da...@gmail.com> Subject: [Haskell-beginners] Re: about the concatenation on a tree To: "Max.cs" <max.cs.2...@googlemail.com> Cc: Beginners Haskell <beginners@haskell.org> Message-ID: <0e6b9c34-eddc-415d-b329-526eebdb1...@gmail.com> Content-Type: text/plain; charset=WINDOWS-1252; format=flowed; delsp=yes On 31 Dec 2008, at 22:38, Max.cs wrote: > Hi Bob, > > Actually I am a fresher in the university and I am doing a > additional exercise for the holiday. > > I think your modification is great, but I am afraid I have to keep > the original forms of the function and data type. I am given the > following code: > >> data Tree a = Leaf a | Branch (Tree a) (Tree a) > >> foldTree :: (a -> b) -> (b -> b -> b) -> Tree a -> b >> foldTree f g (Leaf x) = f x >> foldTree f g (Branch t1 t2) = g (foldTree f g t1) (foldTree f g t2) > > now, what I am asked to do is to complete the following function > concatT using the above foldTree. > >> concatT :: Tree (Tree a) -> Tree a > > the example output of concatT are also given as: > > concatT (Leaf t) = t > concatT (Branch (Leaf t1) (Leaf t2)) = Branch t1 t2 > > I am confused by the type of function concatT and foldTree: > > From the output example, we know, the output should be t (atomic > value) when the input is (Leaf t), and the output will be Branch t1 > t2 (a Branch) when the input is a Branch. But the the definition of > foldTree, the return type of f and g should be the same (both are > b). Am I missing some important point? Any idea on how we can > implement the function concatT ? Sure, but lets go through (most of) the process. We know the function we need has the type Tree (Tree c) -> Tree c. You'll see why I used c as my variable in a minute, and we're given a function with the type (a -> b) -> (b -> b -> b) -> Tree a -> b. Lets try and make that into the type we need. We know the result type must be "Tree c", so lets try replacing all bs with Tree cs: someFunction :: (a -> Tree c) -> (Tree c -> Tree c -> Tree c) -> Tree a -> Tree c We also know that the argument type we want is not a Tree of any values, but actually a Tree of Tree cs, so lets supstitute a for Tree c too: someOtherFunction :: (Tree c -> Tree c) -> (Tree c -> Tree c -> Tree c) -> Tree (Tree c) -> Tree c As we know, in Haskell functions are curried, so this type is the same as (Tree c -> Tree c) -> ((Tree c -> Tree c -> Tree c) -> (Tree (Tree c) -> Tree c)). Note that the last part here is exactly the type we need, so if we provide foldTree with the right two functions, it looks like it's gonna do exactly what we want. Lets look at the rules for foldTree it applies f wherever it meets a Leaf, and g wherever it meets a Branch, so lets think about what we want to do in those two situations. In the case of a Leaf, we'd like to replace the leaf with it's value, so the function we're looking for sounds a lot like it does nothing much. In the case of Branches, we'd like to leave them in place, so we probably want to look at the Branch creator function. I'll leave the rest to you :) > Btw, it will be much better if you do not send this email and the > replies to the maillist for this instance, since I think it is not a > very good idea to let my tutor know I am asking question involved in > the exercise. Just let me know if you dont know you want to answer > this question : ) I'm sure your tutor doesn't mind you asking for help, in fact, he's probably the first guy you should go and ask for some help. What he will want to know is exactly how much help you're getting, and how you're doing with the subject matter remember, he's trying to teach you, not trying to torture you :). Because of that, I have forwarded this email to the mailing list, you're welcome to use my help or not, depending on how guilty you feel (although unless this is a test, any guilt you feel is entirely in error). Bob ------------------------------ Message: 7 Date: Wed, 31 Dec 2008 19:18:11 -0800 From: "Steve Klabnik" <st...@steveklabnik.com> Subject: [Haskell-beginners] until and Time To: beginners@haskell.org Message-ID: <dd81403b0812311918v70bc4949g59fcf7fbb810e...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" Hello everyone. I have a quick question about Time. I was talking about Haskell on the Arch Linux forums today, and someone was trying to put together code that would print a series of periods for, say, 5 minutes. I felt like using 'until' would be the most correct way of going about it, but when I tried to do it... import Time makeLater :: ClockTime -> ClockTime makeLater t = addToClockTime (TimeDiff 0 0 0 0 0 5 0) t updateTime :: ClockTime -> ClockTime updateTime t = t main = do start <- getClockTime until ((==) $ makeLater start) (updateTime) start putStrLn "done" Now, updateTime isn't correct. And this wouldn't print any periods. But GHC is giving me errors: $ runhaskell temp.hs temp.hs:11:2: Couldn't match expected type `IO t' against inferred type `ClockTime' In the expression: until ((==) $ makeLater start) (updateTime) start In a 'do' expression: until ((==) $ makeLater start) (updateTime) start In the expression: do start <- getClockTime until ((==) $ makeLater start) (updateTime) start putStrLn "done" I'm not sure where IO t is coming from at all. Am I even on the right track? How would you write this code? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20081231/9f9a42d1/attachment.htm ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 6, Issue 11 ****************************************