From r.wobben at home.nl Sun Mar 2 18:45:47 2014 From: r.wobben at home.nl (Roelof Wobben) Date: Sun, 02 Mar 2014 19:45:47 +0100 Subject: [Haskell-beginners] where do i get wrong Message-ID: <53137C5B.6070303@home.nl> Hello, I try to selfstudy haskell by following the yet another haskell tutorial. Now I have the exercise where I have a string and have to convert it into a list of Booleans based on lower cats letter using map. So i tried this x = "aBCde".islower:[] But I see this error : Not in Scope: 'isLower'. Where do I make my error. Do not give the answer otherwise I do not learn anything from it. Roelof --- Dit e-mailbericht bevat geen virussen en malware omdat avast! Antivirus-bescherming actief is. http://www.avast.com From bob at redivi.com Sun Mar 2 19:02:05 2014 From: bob at redivi.com (Bob Ippolito) Date: Sun, 2 Mar 2014 11:02:05 -0800 Subject: [Haskell-beginners] where do i get wrong In-Reply-To: <53137C5B.6070303@home.nl> References: <53137C5B.6070303@home.nl> Message-ID: isLower is not in the Prelude (the automatically imported module built-in functions). Here's the list of all functions in Prelude: http://hackage.haskell.org/package/base/docs/Prelude.html isLower is in another module. You can figure that out by searching for "isLower" on Hoogle: http://www.haskell.org/hoogle/ You can even find it by searching for it by type, which is useful if you don't remember the precise name. Try searching for "Char -> Bool". In other words, you'll need to import isLower from somewhere before you can use it. On Sun, Mar 2, 2014 at 10:45 AM, Roelof Wobben wrote: > Hello, > > I try to selfstudy haskell by following the yet another haskell tutorial. > > Now I have the exercise where I have a string and have to convert it into > a list of Booleans based on lower cats letter using map. > > So i tried this > > x = "aBCde".islower:[] > > But I see this error : Not in Scope: 'isLower'. > > Where do I make my error. > > Do not give the answer otherwise I do not learn anything from it. > > Roelof > > > --- > Dit e-mailbericht bevat geen virussen en malware omdat avast! > Antivirus-bescherming actief is. > http://www.avast.com > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Sun Mar 2 19:10:02 2014 From: r.wobben at home.nl (Roelof Wobben) Date: Sun, 02 Mar 2014 20:10:02 +0100 Subject: [Haskell-beginners] where do i get wrong In-Reply-To: References: <53137C5B.6070303@home.nl> Message-ID: <5313820A.7050806@home.nl> An HTML attachment was scrubbed... URL: From bob at redivi.com Sun Mar 2 19:14:40 2014 From: bob at redivi.com (Bob Ippolito) Date: Sun, 2 Mar 2014 11:14:40 -0800 Subject: [Haskell-beginners] where do i get wrong In-Reply-To: <5313820A.7050806@home.nl> References: <53137C5B.6070303@home.nl> <5313820A.7050806@home.nl> Message-ID: Packages and modules are not the same thing. Packages contain one or more modules, they're typically just units of installation and not so much something you deal with in the code. If the tutorial hasn't talked about importing modules, then it's wrong. Perhaps it's simply ancient and is written for some historical version of Haskell that had these in Prelude? isLower is not part of Prelude, so you must import it from somewhere. The IDE you're using is irrelevant. On Sun, Mar 2, 2014 at 11:10 AM, Roelof Wobben wrote: > Thanks, > > isLower is in base package. > The tutorial has not spoken about importing modules. > > I use the IDE of fpcomplete. > > Roelof > > > > Bob Ippolito schreef op 2-3-2014 20:02: > > isLower is not in the Prelude (the automatically imported module built-in > functions). Here's the list of all functions in Prelude: > http://hackage.haskell.org/package/base/docs/Prelude.html > > isLower is in another module. You can figure that out by searching for > "isLower" on Hoogle: > http://www.haskell.org/hoogle/ > > You can even find it by searching for it by type, which is useful if you > don't remember the precise name. Try searching for "Char -> Bool". > > In other words, you'll need to import isLower from somewhere before you > can use it. > > > > On Sun, Mar 2, 2014 at 10:45 AM, Roelof Wobben wrote: > >> Hello, >> >> I try to selfstudy haskell by following the yet another haskell tutorial. >> >> Now I have the exercise where I have a string and have to convert it into >> a list of Booleans based on lower cats letter using map. >> >> So i tried this >> >> x = "aBCde".islower:[] >> >> But I see this error : Not in Scope: 'isLower'. >> >> Where do I make my error. >> >> Do not give the answer otherwise I do not learn anything from it. >> >> Roelof >> >> >> --- >> Dit e-mailbericht bevat geen virussen en malware omdat avast! >> Antivirus-bescherming actief is. >> http://www.avast.com >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://www.haskell.org/mailman/listinfo/beginners >> > > > > _______________________________________________ > Beginners mailing listBeginners at haskell.orghttp://www.haskell.org/mailman/listinfo/beginners > > > > > ------------------------------ > > > Dit e-mailbericht bevat geen virussen en malware omdat avast! Antivirusactief is. > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Sun Mar 2 19:24:56 2014 From: r.wobben at home.nl (Roelof Wobben) Date: Sun, 02 Mar 2014 20:24:56 +0100 Subject: [Haskell-beginners] where do i get wrong In-Reply-To: <5313820A.7050806@home.nl> References: <53137C5B.6070303@home.nl> <5313820A.7050806@home.nl> Message-ID: <53138588.2070108@home.nl> An HTML attachment was scrubbed... URL: From ryanstradling at gmail.com Sun Mar 2 19:44:41 2014 From: ryanstradling at gmail.com (Ryan Stradling) Date: Sun, 2 Mar 2014 14:44:41 -0500 Subject: [Haskell-beginners] where do i get wrong In-Reply-To: <53138588.2070108@home.nl> References: <53137C5B.6070303@home.nl> <5313820A.7050806@home.nl> <53138588.2070108@home.nl> Message-ID: isLower takes a character. You need to look at operating on the string with higher order functions which will call isLower on each character. On Mar 2, 2014 2:25 PM, "Roelof Wobben" wrote: > Found this one: > > This is partly working: > > import Data.Char > > x = "aBCde".isLower > -- Note that comments are preceded by two hyphens > {- or enclosed > in curly brace/hypens pairs. -} > main = print x > > > But now I see this error: > > - Main.hs at 3:5-3:12 > Couldn't match expected type `b0 -> c0' with actual type `[Char]' In > the first argument of `(.)', namely `"aBCde"' In the expression: "aBCde" . > isLower In an equation for `x': x = "aBCde" . isLower > - In an equation for `x': x = "aBCde" . isLower > > > Roelof > > Roelof Wobben schreef op 2-3-2014 20:10: > > Thanks, > > isLower is in base package. > The tutorial has not spoken about importing modules. > > I use the IDE of fpcomplete. > > Roelof > > > > Bob Ippolito schreef op 2-3-2014 20:02: > > isLower is not in the Prelude (the automatically imported module built-in > functions). Here's the list of all functions in Prelude: > http://hackage.haskell.org/package/base/docs/Prelude.html > > isLower is in another module. You can figure that out by searching for > "isLower" on Hoogle: > http://www.haskell.org/hoogle/ > > You can even find it by searching for it by type, which is useful if you > don't remember the precise name. Try searching for "Char -> Bool". > > In other words, you'll need to import isLower from somewhere before you > can use it. > > > > On Sun, Mar 2, 2014 at 10:45 AM, Roelof Wobben wrote: > >> Hello, >> >> I try to selfstudy haskell by following the yet another haskell tutorial. >> >> Now I have the exercise where I have a string and have to convert it into >> a list of Booleans based on lower cats letter using map. >> >> So i tried this >> >> x = "aBCde".islower:[] >> >> But I see this error : Not in Scope: 'isLower'. >> >> Where do I make my error. >> >> Do not give the answer otherwise I do not learn anything from it. >> >> Roelof >> >> >> --- >> Dit e-mailbericht bevat geen virussen en malware omdat avast! >> Antivirus-bescherming actief is. >> http://www.avast.com >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://www.haskell.org/mailman/listinfo/beginners >> > > > > _______________________________________________ > Beginners mailing listBeginners at haskell.orghttp://www.haskell.org/mailman/listinfo/beginners > > > > > ------------------------------ > > > Dit e-mailbericht bevat geen virussen en malware omdat avast! Antivirusactief is. > > > > _______________________________________________ > Beginners mailing listBeginners at haskell.orghttp://www.haskell.org/mailman/listinfo/beginners > > > > > ------------------------------ > > > Dit e-mailbericht bevat geen virussen en malware omdat avast! Antivirusactief is. > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Sun Mar 2 19:50:09 2014 From: r.wobben at home.nl (Roelof Wobben) Date: Sun, 02 Mar 2014 20:50:09 +0100 Subject: [Haskell-beginners] where do i get wrong In-Reply-To: References: <53137C5B.6070303@home.nl> <5313820A.7050806@home.nl> <53138588.2070108@home.nl> Message-ID: <53138B71.6040303@home.nl> An HTML attachment was scrubbed... URL: From poczta at emanuelkoczwara.pl Sun Mar 2 19:54:13 2014 From: poczta at emanuelkoczwara.pl (Emanuel Koczwara) Date: Sun, 02 Mar 2014 20:54:13 +0100 Subject: [Haskell-beginners] where do i get wrong In-Reply-To: <53138588.2070108@home.nl> References: <53137C5B.6070303@home.nl> <5313820A.7050806@home.nl> <53138588.2070108@home.nl> Message-ID: <53138C65.2080002@emanuelkoczwara.pl> Hi, W dniu 02.03.2014 20:24, Roelof Wobben pisze: > Found this one: > > This is partly working: > > import Data.Char > > x = "aBCde".isLower > -- Note that comments are preceded by two hyphens > {- or enclosed > in curly brace/hypens pairs. -} > main = print x > > > But now I see this error: > > * > Main.hs at 3:5-3:12 > Couldn't match expected type `b0 -> c0' with actual type `[Char]' > In the first argument of `(.)', namely `"aBCde"' In the > expression: "aBCde" . isLower In an equation for `x': x = "aBCde" > . isLower > * > In an equation for `x': x = "aBCde" . isLower > > > Roelof This expression is wrong: "aBCde".isLower You call (.) function with 2 arguments: "aBCde" and isLower. This doesn't make sense for the compiler (type checker). Regards, Emanuel -------------- next part -------------- An HTML attachment was scrubbed... URL: From vlatko.basic at gmail.com Sun Mar 2 19:58:24 2014 From: vlatko.basic at gmail.com (Vlatko Basic) Date: Sun, 02 Mar 2014 20:58:24 +0100 Subject: [Haskell-beginners] where do i get wrong In-Reply-To: <53138B71.6040303@home.nl> References: <53137C5B.6070303@home.nl> <5313820A.7050806@home.nl> <53138588.2070108@home.nl> <53138B71.6040303@home.nl> Message-ID: <53138D60.4030104@gmail.com> An HTML attachment was scrubbed... URL: From r.wobben at home.nl Sun Mar 2 20:06:06 2014 From: r.wobben at home.nl (Roelof Wobben) Date: Sun, 02 Mar 2014 21:06:06 +0100 Subject: [Haskell-beginners] where do i get wrong In-Reply-To: <53138D60.4030104@gmail.com> References: <53137C5B.6070303@home.nl> <5313820A.7050806@home.nl> <53138588.2070108@home.nl> <53138B71.6040303@home.nl> <53138D60.4030104@gmail.com> Message-ID: <53138F2E.9040505@home.nl> An HTML attachment was scrubbed... URL: From poczta at emanuelkoczwara.pl Sun Mar 2 20:12:03 2014 From: poczta at emanuelkoczwara.pl (Emanuel Koczwara) Date: Sun, 02 Mar 2014 21:12:03 +0100 Subject: [Haskell-beginners] where do i get wrong In-Reply-To: <53138F2E.9040505@home.nl> References: <53137C5B.6070303@home.nl> <5313820A.7050806@home.nl> <53138588.2070108@home.nl> <53138B71.6040303@home.nl> <53138D60.4030104@gmail.com> <53138F2E.9040505@home.nl> Message-ID: <53139093.9050509@emanuelkoczwara.pl> Hi, W dniu 02.03.2014 21:06, Roelof Wobben pisze: > Thanks. > > This does the job : > > import Data.Char > > x = map isLower "ABCde":[] > -- Note that comments are preceded by two hyphens > {- or enclosed > in curly brace/hypens pairs. -} > main = print x > You have a list of lists of booleans: [[Bool]]. You should get a list of booleans: [Bool] instead. Regards, Emanuel -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Sun Mar 2 20:32:16 2014 From: r.wobben at home.nl (Roelof Wobben) Date: Sun, 02 Mar 2014 21:32:16 +0100 Subject: [Haskell-beginners] where do i get wrong In-Reply-To: <53139093.9050509@emanuelkoczwara.pl> References: <53137C5B.6070303@home.nl> <5313820A.7050806@home.nl> <53138588.2070108@home.nl> <53138B71.6040303@home.nl> <53138D60.4030104@gmail.com> <53138F2E.9040505@home.nl> <53139093.9050509@emanuelkoczwara.pl> Message-ID: <53139550.3050606@home.nl> An HTML attachment was scrubbed... URL: From nadirsampaoli at gmail.com Sun Mar 2 20:36:33 2014 From: nadirsampaoli at gmail.com (Nadir Sampaoli) Date: Sun, 2 Mar 2014 21:36:33 +0100 Subject: [Haskell-beginners] where do i get wrong In-Reply-To: <53138B71.6040303@home.nl> References: <53137C5B.6070303@home.nl> <5313820A.7050806@home.nl> <53138588.2070108@home.nl> <53138B71.6040303@home.nl> Message-ID: Hello, 2014-03-02 20:50 GMT+01:00 Roelof Wobben : > Correect, I forget to use map > But also x = map "aBCde".islower does not work. > > Your use of the dot (.) function makes me think you might mix Haskell syntax with OO languages like Python or Java where dot notation is used to call methods on objects. Also, as Emanuel and Vlatko pointed out one very important thing in Haskell is reading type signatures. So, let's check `map` signature: map :: (a -> b) -> [a] -> [b] What does this mean? Although all Haskell functions take one and only one argument we probably might find it simpler to reason in terms of first argument, second argument and return value (`map` should probably be better described as a function that takes a function from `a` to `b` and returns a function from [a] to [b]). Anyway. The first argument is (a -> b), a function from `a` to `b`. The second argument is [a], i.e. a list of `a` (`a` can potentially represent any type). The last type in the signature is [b] which we might call the return type. Again, haskellers, don't stab me please :) Now check the type signature for `isLower`: isLower :: Char -> Bool `isLower` will be `map`'s first argument, so, replacing the original (a -> b) with isLower type signature, you'll get: map :: (Char -> Bool) -> [Char] -> [Bool] A step further, the signature then becomes: map isLower :: [Char] -> [Bool] As you can see here, understanding that all functions in Haskell takes just one argument helps because `map isLower` is in turn a function. The result of calling `map` with `isLower` as its (first and only) argument, is a function from [a], or, better, from [Char], since Char is the (first and only) argument of `isLower`, to [b], or, better, to [Bool] since Bool is the return type of `isLower`. Now we have map isLower which takes a [Char]. [Char] and String are synonyms, by the way, so you could also write `map isLower` signature as follows: map isLower :: String -> [Bool] This seems exactly what we need: a function from String to a list of booleans. I think I have to find out how I can ghci in fpcomplete or use another IDE > which supports it. > > Roelof > Have you read/are you reading "Learn you a Haskell" ( http://learnyouahaskell.com/chapters)? I'd advise you to read it, as it helps you, in the beginning, being more confortable with Haskell's syntax and library. -- Nadir -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Sun Mar 2 21:44:14 2014 From: r.wobben at home.nl (Roelof Wobben) Date: Sun, 02 Mar 2014 22:44:14 +0100 Subject: [Haskell-beginners] foldr problem Message-ID: <5313A62E.7060101@home.nl> An HTML attachment was scrubbed... URL: From poczta at emanuelkoczwara.pl Sun Mar 2 21:51:51 2014 From: poczta at emanuelkoczwara.pl (Emanuel Koczwara) Date: Sun, 02 Mar 2014 22:51:51 +0100 Subject: [Haskell-beginners] foldr problem In-Reply-To: <5313A62E.7060101@home.nl> References: <5313A62E.7060101@home.nl> Message-ID: <5313A7F7.3020505@emanuelkoczwara.pl> Hi, W dniu 02.03.2014 22:44, Roelof Wobben pisze: > Hello, > > I now have to use foldr to find the max value in a list. > > So I do this: > > import Data.Char > > x = foldr max [5,10,2,8.1] > -- Note that comments are preceded by two hyphens > {- or enclosed > in curly brace/hypens pairs. -} > main = print x > > But now I see this error message: > Active code from: 1: Haskell Basics > main.hs at 7:8-7:13 > No instance for (Show ([[t0]] -> [t0])) arising from a use of > `print' Possible fix: add an instance declaration for (Show ([[t0]] -> > [t0])) In the expression: print x In an equation for `main': main = > print x > > Active code from: 1: Haskell Basics Active code from: 1: Haskell Basics Please look at foldr type and documentation. There is one argument missing in your code. Regards, Emanuel -------------- next part -------------- An HTML attachment was scrubbed... URL: From kmandpjlynch at verizon.net Mon Mar 3 00:53:52 2014 From: kmandpjlynch at verizon.net (KMandPJLynch) Date: Sun, 02 Mar 2014 19:53:52 -0500 Subject: [Haskell-beginners] "Developing Web Applications with Haskell and Yesod" Message-ID: <5AE2BD87-D8A7-49E6-905B-2C138CB78C2A@verizon.net> I'm reading the O'Reilly book "Developing Web Applications with Haskell and Yesod" but can't get the helloworld.hs app, from the book, to work. This is what I did: 1. I downloaded Haskell and it works just fine. 2. cabal update 3. cabal install yesod 4. I downloaded the helloworld.hs program - see following: {-# LANGUAGE TypeFamilies, QuasiQuotes, MultiParamTypeClasses, TemplateHaskell, OverloadedStrings #-} import Yesod data HelloWorld = HelloWorld mkYesod "HelloWorld" [parseRoutes] / HomeR Get|] instance Yesod HelloWorld getHomeR :: Handler RepHtml getHomeR = defaultLayout [whamlet[|Hell World!|] main :: IO () main = warpDebug 3000 HelloWorld 5. I went to the terminal on a Mac and entered command: runhaskell helloworld.hs 6. on the terminal the following is displayed: Hell World! 7. I opened a Safari browser and entered: http://localhost:3000 8. the following error message is displayed: "Safari can't connect to Server. Safari can't open the page http://localhost:3000/ because Safari can't connect to localhost" I'd appreciate any help. From byorgey at seas.upenn.edu Mon Mar 3 02:33:07 2014 From: byorgey at seas.upenn.edu (Brent Yorgey) Date: Sun, 2 Mar 2014 21:33:07 -0500 Subject: [Haskell-beginners] "Developing Web Applications with Haskell and Yesod" In-Reply-To: <5AE2BD87-D8A7-49E6-905B-2C138CB78C2A@verizon.net> References: <5AE2BD87-D8A7-49E6-905B-2C138CB78C2A@verizon.net> Message-ID: <20140303023306.GA13289@seas.upenn.edu> On Sun, Mar 02, 2014 at 07:53:52PM -0500, KMandPJLynch wrote: > 7. I opened a Safari browser and entered: http://localhost:3000 > 8. the following error message is displayed: > "Safari can't connect to Server. > Safari can't open the page http://localhost:3000/ because Safari can't connect to localhost" Try a different browser. I think I've heard similar problems mentioned before where the problem was some bug/lack of feature in Safari. -Brent From tyler.huffman at tylerh.org Mon Mar 3 05:33:50 2014 From: tyler.huffman at tylerh.org (Tyler Huffman) Date: Sun, 2 Mar 2014 22:33:50 -0700 Subject: [Haskell-beginners] Question about Ord for lists and multi-dimensional lists Message-ID: Hi all, I'm having trouble finding resources explaining how Ord for two lists works. I've created a public gist to explain what I mean. https://gist.github.com/iduhetonas/9318958 Could anybody shed some light on what I'm seeing? Regards, Tyler Huffman -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuuzetsu at fuuzetsu.co.uk Mon Mar 3 05:44:58 2014 From: fuuzetsu at fuuzetsu.co.uk (Mateusz Kowalczyk) Date: Mon, 03 Mar 2014 05:44:58 +0000 Subject: [Haskell-beginners] Question about Ord for lists and multi-dimensional lists In-Reply-To: References: Message-ID: <531416DA.1020808@fuuzetsu.co.uk> On 03/03/14 05:33, Tyler Huffman wrote: > Hi all, > > I'm having trouble finding resources explaining how Ord for two lists works. > > I've created a public gist to explain what I mean. > > https://gist.github.com/iduhetonas/9318958 > > Could anybody shed some light on what I'm seeing? > > > Regards, > Tyler Huffman > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > It does element-wise comparisons and in case one of the lists is empty, the other one is considered greater (unless they are both empty). So: Prelude> max [1] [2] Here 2 is bigger than 1 so we get the result straight away Prelude> max [1,2] [1] Here the first element is equal so we compare the rest of lists: [2] and []. As the second list is empty, we return the first list. Prelude> max [2,1] [1] No problem at all here, 2 is greater than 1 so we just return the first list on the first comparison. Prelude> max [1,2] [1,2,4] This is exactly the same case as ?max [1, 2] [1]?: we first compare the 1s, find they are equal and compare the rest of the list. Same with 2s. Then the base case is ?max [] [4]? so the second list is treated as greater. Prelude> max [1,2,4] [1,2] Same as above but with arguments switched. I believe that the law here is ?max x y ? max y x?. Prelude> max [[1,2,3],[2,3,4]] [[1,2],[2,3],[2,4]] This is just like all our other examples except one more level of nesting. We first end up comparing the first elements of the argument (so we call out ?max [1, 2, 3] [1, 2]?, and then check each element of these lists. 1 and 2 are equal and we reach the ?max [3] []? case: the first list was greater so our whole call returns ?[[1, 2, 3], [2, 3, 4]]?. I hope that sheds some light. -- Mateusz K. From tyler.huffman at tylerh.org Mon Mar 3 05:47:13 2014 From: tyler.huffman at tylerh.org (Tyler Huffman) Date: Sun, 2 Mar 2014 22:47:13 -0700 Subject: [Haskell-beginners] Question about Ord for lists and multi-dimensional lists In-Reply-To: <531416DA.1020808@fuuzetsu.co.uk> References: <531416DA.1020808@fuuzetsu.co.uk> Message-ID: Awesome, that helps a lot. Thanks a bunch, Mateusz! Regards, Tyler Huffman On Sun, Mar 2, 2014 at 10:44 PM, Mateusz Kowalczyk wrote: > On 03/03/14 05:33, Tyler Huffman wrote: > > Hi all, > > > > I'm having trouble finding resources explaining how Ord for two lists > works. > > > > I've created a public gist to explain what I mean. > > > > https://gist.github.com/iduhetonas/9318958 > > > > Could anybody shed some light on what I'm seeing? > > > > > > Regards, > > Tyler Huffman > > > > > > > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://www.haskell.org/mailman/listinfo/beginners > > > > It does element-wise comparisons and in case one of the lists is empty, > the other one is considered greater (unless they are both empty). > > So: > Prelude> max [1] [2] > > Here 2 is bigger than 1 so we get the result straight away > > Prelude> max [1,2] [1] > > Here the first element is equal so we compare the rest of lists: [2] and > []. As the second list is empty, we return the first list. > > Prelude> max [2,1] [1] > > No problem at all here, 2 is greater than 1 so we just return the first > list on the first comparison. > > Prelude> max [1,2] [1,2,4] > > This is exactly the same case as ?max [1, 2] [1]?: we first compare the > 1s, find they are equal and compare the rest of the list. Same with 2s. > Then the base case is ?max [] [4]? so the second list is treated as > greater. > > Prelude> max [1,2,4] [1,2] > > Same as above but with arguments switched. I believe that the law here > is ?max x y ? max y x?. > > Prelude> max [[1,2,3],[2,3,4]] [[1,2],[2,3],[2,4]] > > This is just like all our other examples except one more level of > nesting. We first end up comparing the first elements of the argument > (so we call out ?max [1, 2, 3] [1, 2]?, and then check each element of > these lists. 1 and 2 are equal and we reach the ?max [3] []? case: the > first list was greater so our whole call returns ?[[1, 2, 3], [2, 3, 4]]?. > > I hope that sheds some light. > > -- > Mateusz K. > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Mon Mar 3 06:51:06 2014 From: r.wobben at home.nl (Roelof Wobben) Date: Mon, 03 Mar 2014 07:51:06 +0100 Subject: [Haskell-beginners] foldr problem In-Reply-To: <5313A7F7.3020505@emanuelkoczwara.pl> References: <5313A62E.7060101@home.nl> <5313A7F7.3020505@emanuelkoczwara.pl> Message-ID: <5314265A.5050903@home.nl> An HTML attachment was scrubbed... URL: From ky3 at atamo.com Mon Mar 3 07:25:12 2014 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Mon, 3 Mar 2014 14:25:12 +0700 Subject: [Haskell-beginners] Question about Ord for lists and multi-dimensional lists In-Reply-To: References: Message-ID: On Mon, Mar 3, 2014 at 12:33 PM, Tyler Huffman wrote: > Could anybody shed some light on what I'm seeing? This is the standard lex order you see in dictionaries. The word "a" is followed by "aardvark" which is in turn followed by "an". Similarly [1] is followed by [1,2] which is in turn followed by [1,2,4]. (It's possible to override the order.) -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From akaberto at gmail.com Mon Mar 3 11:03:22 2014 From: akaberto at gmail.com (akash g) Date: Mon, 3 Mar 2014 16:33:22 +0530 Subject: [Haskell-beginners] foldr problem In-Reply-To: <5314265A.5050903@home.nl> References: <5313A62E.7060101@home.nl> <5313A7F7.3020505@emanuelkoczwara.pl> <5314265A.5050903@home.nl> Message-ID: Or you can try foldr1, which doesn't need a terminating value. Here's its definition from the Standard Prelude foldr1 :: (a -> a -> a) -> [a] -> afoldr1 _ [x] = xfoldr1 f (x:xs) = f x (foldr1 f xs)foldr1 _ [] = errorEmptyList "foldr1" On Mon, Mar 3, 2014 at 12:21 PM, Roelof Wobben wrote: > Thanks, > > This did the job: > > import Data.Char > > x = foldr max 0 [5,10,2,8,1] > > -- Note that comments are preceded by two hyphens > {- or enclosed > in curly brace/hypens pairs. -} > main = print x > > Roelof > > > Emanuel Koczwara schreef op 2-3-2014 22:51: > > Hi, > > W dniu 02.03.2014 22:44, Roelof Wobben pisze: > > Hello, > > I now have to use foldr to find the max value in a list. > > So I do this: > > import Data.Char > > x = foldr max [5,10,2,8.1] > -- Note that comments are preceded by two hyphens > {- or enclosed > in curly brace/hypens pairs. -} > main = print x > > But now I see this error message: > > main.hs at 7:8-7:13 > No instance for (Show ([[t0]] -> [t0])) arising from a use of `print' > Possible fix: add an instance declaration for (Show ([[t0]] -> [t0])) In > the expression: print x In an equation for `main': main = print x > > > > Please look at foldr type and documentation. There is one argument > missing in your code. > > Regards, > Emanuel > > > > _______________________________________________ > Beginners mailing listBeginners at haskell.orghttp://www.haskell.org/mailman/listinfo/beginners > > > > > ------------------------------ > > > Dit e-mailbericht bevat geen virussen en malware omdat avast! Antivirusactief is. > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nathan.huesken at posteo.de Mon Mar 3 15:10:05 2014 From: nathan.huesken at posteo.de (=?ISO-8859-1?Q?Nathan_H=FCsken?=) Date: Mon, 03 Mar 2014 16:10:05 +0100 Subject: [Haskell-beginners] Good way of combining functions of type IO (Maybe a) Message-ID: <53149B4D.3070002@posteo.de> Hey, I want to write a function, which is basically a concatenation of functions of type "IO (Maybe a)". When they all where of type "Maybe a", no Problem I would simple use the Maybe monad. |func :: Maybe c func = do a <- f1 b <- d2 a ... | but now they are of type "IO (Maybe a)". Is there some way of combing these in a similar smart way? Thanks! Nathan -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: OpenPGP digital signature URL: From toad3k at gmail.com Mon Mar 3 15:21:03 2014 From: toad3k at gmail.com (David McBride) Date: Mon, 3 Mar 2014 10:21:03 -0500 Subject: [Haskell-beginners] Good way of combining functions of type IO (Maybe a) In-Reply-To: <53149B4D.3070002@posteo.de> References: <53149B4D.3070002@posteo.de> Message-ID: cabal install maybet import Control.Monad.Maybe f1 :: IO (Maybe Int) f1 = return . Just $ 1 d2 :: Int -> IO (Maybe String) d2 = return . Just . show blah :: IO (Maybe (Int, String)) blah = do runMaybeT $ do a <- MaybeT f1 b <- MaybeT $ d2 a return (a,b) Or slightly rewritten: f1 :: MaybeT IO Int f1 = return 1 -- f1 = fail "why oh why?!?" d2 :: Int -> MaybeT IO String d2 = return . show blah = do runMaybeT $ do a <- f1 b <- d2 a return (a,b) On Mon, Mar 3, 2014 at 10:10 AM, Nathan H?sken wrote: > Hey, > > I want to write a function, which is basically a concatenation of > functions of type "IO (Maybe a)". > When they all where of type "Maybe a", no Problem I would simple use the > Maybe monad. > > func :: Maybe cfunc = do > a <- f1 > b <- d2 a > ... > > but now they are of type "IO (Maybe a)". Is there some way of combing > these in a similar smart way? > > Thanks! > Nathan > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Mon Mar 3 16:55:34 2014 From: r.wobben at home.nl (Roelof Wobben) Date: Mon, 03 Mar 2014 17:55:34 +0100 Subject: [Haskell-beginners] list problem Message-ID: <5314B406.7030102@home.nl> Hello, I have this : cons8 n l = n : l x = cons8 8 [1,2,3] main = print x This will be the output: [8.1.2.3] Now the problem is how I can take care that the output will be [1,2,3,4,8] I have to change the function for it. I tried switching n and L in the function but that will not work. Or does I have to do x = cons [1,2,3] 8 and make the function like this cons8 l n = l : n Roelof --- Dit e-mailbericht bevat geen virussen en malware omdat avast! Antivirus-bescherming actief is. http://www.avast.com From edwards.benj at gmail.com Mon Mar 3 16:59:16 2014 From: edwards.benj at gmail.com (Benjamin Edwards) Date: Mon, 03 Mar 2014 16:59:16 +0000 Subject: [Haskell-beginners] list problem References: <5314B406.7030102@home.nl> Message-ID: The problem is that you don't seem to understand how singly linked lists work. I would recommend studying this first, then understanding how to append a value to the end of the list in haskell will probably make a lot more sense. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris at christopher-schneider.com Mon Mar 3 17:00:26 2014 From: chris at christopher-schneider.com (Chris Schneider) Date: Mon, 3 Mar 2014 10:00:26 -0700 Subject: [Haskell-beginners] Good way of combining functions of type IO (Maybe a) In-Reply-To: References: <53149B4D.3070002@posteo.de> Message-ID: I'm a beginner as well, and I explored how to use the maybeT transformer and wrote it up on my blog across a few posts. Mostly they were just for my own learning purposes, but maybe you can find something in them too? http://watchchrislearn.com/blog/2013/11/28/playing-with-the-either-monad/ http://watchchrislearn.com/blog/2013/11/30/using-the-either-monad-inside-another-monad/ http://watchchrislearn.com/blog/2013/11/30/eithert-inside-of-io/ http://watchchrislearn.com/blog/2013/12/01/working-entirely-in-eithert/ On Mon, Mar 3, 2014 at 8:21 AM, David McBride wrote: > cabal install maybet > > import Control.Monad.Maybe > > f1 :: IO (Maybe Int) > f1 = return . Just $ 1 > > d2 :: Int -> IO (Maybe String) > d2 = return . Just . show > > blah :: IO (Maybe (Int, String)) > blah = do > runMaybeT $ do > a <- MaybeT f1 > b <- MaybeT $ d2 a > return (a,b) > > Or slightly rewritten: > > f1 :: MaybeT IO Int > f1 = return 1 > -- f1 = fail "why oh why?!?" > > d2 :: Int -> MaybeT IO String > d2 = return . show > > blah = do > runMaybeT $ do > > a <- f1 > b <- d2 a > return (a,b) > > > > On Mon, Mar 3, 2014 at 10:10 AM, Nathan H?sken wrote: > >> Hey, >> >> I want to write a function, which is basically a concatenation of >> functions of type "IO (Maybe a)". >> When they all where of type "Maybe a", no Problem I would simple use the >> Maybe monad. >> >> func :: Maybe cfunc = do >> a <- f1 >> b <- d2 a >> ... >> >> but now they are of type "IO (Maybe a)". Is there some way of combing >> these in a similar smart way? >> >> Thanks! >> Nathan >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://www.haskell.org/mailman/listinfo/beginners >> >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Mon Mar 3 17:04:01 2014 From: r.wobben at home.nl (Roelof Wobben) Date: Mon, 03 Mar 2014 18:04:01 +0100 Subject: [Haskell-beginners] list problem In-Reply-To: References: <5314B406.7030102@home.nl> Message-ID: <5314B601.1@home.nl> An HTML attachment was scrubbed... URL: From poczta at emanuelkoczwara.pl Mon Mar 3 17:40:03 2014 From: poczta at emanuelkoczwara.pl (Emanuel Koczwara) Date: Mon, 03 Mar 2014 18:40:03 +0100 Subject: [Haskell-beginners] list problem In-Reply-To: <5314B601.1@home.nl> References: <5314B406.7030102@home.nl> <5314B601.1@home.nl> Message-ID: <5314BE73.7080705@emanuelkoczwara.pl> Hi, W dniu 03.03.2014 18:04, Roelof Wobben pisze: > I am studing this by following the wiki tutorial and then the Haskell > basic tutorial. > But if you have a better tutorial I'm happy to study this one too. > > Roelof > > > > Benjamin Edwards schreef op 3-3-2014 17:59: >> The problem is that you don't seem to understand how singly linked >> lists work. I would recommend studying this first, then understanding >> how to append a value to the end of the list in haskell will probably >> make a lot more sense. >> >> >> This is of course mailing list for beginners and we are happy to help you, but your questions are _very_ basic. Please take a look at http://learnyouahaskell.com. Regards, Emanuel -------------- next part -------------- An HTML attachment was scrubbed... URL: From tyler.huffman at tylerh.org Mon Mar 3 17:49:16 2014 From: tyler.huffman at tylerh.org (Tyler Huffman) Date: Mon, 3 Mar 2014 10:49:16 -0700 Subject: [Haskell-beginners] list problem Message-ID: I would definitely recommend the #haskell IRC channel for simple questions as well. Usually they're better at less complicated questions than the Haskell Beginner mailing list. Here's a link for some more information: ( http://www.haskell.org/haskellwiki/IRC_channel) Best of luck! On Mon, Mar 3, 2014 at 10:40 AM, Emanuel Koczwara wrote: > Hi, > > W dniu 03.03.2014 18:04, Roelof Wobben pisze: > > I am studing this by following the wiki tutorial and then the Haskell > basic tutorial. > But if you have a better tutorial I'm happy to study this one too. > > Roelof > > > > Benjamin Edwards schreef op 3-3-2014 17:59: > > The problem is that you don't seem to understand how singly linked lists > work. I would recommend studying this first, then understanding how to > append a value to the end of the list in haskell will probably make a lot > more sense. > > >> > > This is of course mailing list for beginners and we are happy to help > you, but your questions are _very_ basic. Please take a look at > http://learnyouahaskell.com. > > Regards, > Emanuel > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > Regards, Tyler Huffman -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim.v2.0 at gmail.com Mon Mar 3 18:45:51 2014 From: tim.v2.0 at gmail.com (Tim Perry) Date: Mon, 3 Mar 2014 10:45:51 -0800 Subject: [Haskell-beginners] "Developing Web Applications with Haskell and Yesod" In-Reply-To: <20140303023306.GA13289@seas.upenn.edu> References: <5AE2BD87-D8A7-49E6-905B-2C138CB78C2A@verizon.net> <20140303023306.GA13289@seas.upenn.edu> Message-ID: The code you posted won't run for me as listed. Several errors keep it from running. Namely, the are several extra "[" characters and "Get" should be "GET". Once I fixed those, the code works fine in both Chrome and Safari on my Mac. Depending on the versions of the OS, Haskell Platform, Yesod, et cetera your result may vary. Good luck, Tim On Sun, Mar 2, 2014 at 6:33 PM, Brent Yorgey wrote: > On Sun, Mar 02, 2014 at 07:53:52PM -0500, KMandPJLynch wrote: > > 7. I opened a Safari browser and entered: http://localhost:3000 > > 8. the following error message is displayed: > > "Safari can't connect to Server. > > Safari can't open the page http://localhost:3000/ because Safari > can't connect to localhost" > > Try a different browser. I think I've heard similar problems > mentioned before where the problem was some bug/lack of feature in > Safari. > > -Brent > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gale at sefer.org Tue Mar 4 07:13:54 2014 From: gale at sefer.org (Yitzchak Gale) Date: Tue, 4 Mar 2014 09:13:54 +0200 Subject: [Haskell-beginners] Good way of combining functions of type IO (Maybe a) In-Reply-To: References: <53149B4D.3070002@posteo.de> Message-ID: Nathan H?sken wrote: >> I want to write a function, which is basically a concatenation of >> functions of type "IO (Maybe a)". David McBride wrote: > cabal install maybet I would recommend using the standard MaybeT type, from the transformers library that is part of the Haskell Platform, unless you have a special reason to use a different library from Hackage. David's code works fine with the transformers library, after a slight modification of the import: import Control.Monad.Trans.Maybe Also - using the MaybeT monad is not the only way to do this. Maybe comes with a whole collection of very convenient combinators like "maybe", "fromMaybe", etc. So you can also do the calculation entirely in just IO without very much extra noice. Choose the approach that works out nicest for your particular application. Here is David's code, modified to do the calculations directly in the IO monad: f1 :: IO (Maybe Int) f1 = return . Just $ 1 d2 :: Int -> IO (Maybe String) d2 = return . Just . show blah :: IO (Maybe (Int, String)) blah = do a <- f1 b <- maybe (return Nothing) d2 a return (a,b) If you end up using things like "maybe (return Nothing)" and "fromMaybe (return Nothing)" a lot, you can define aliases for them. Perhaps there ought to be aliases like that in the standard libraries somewhere... Regards, Yitz From voldermort at hotmail.com Tue Mar 4 10:11:36 2014 From: voldermort at hotmail.com (harry) Date: Tue, 4 Mar 2014 10:11:36 +0000 (UTC) Subject: [Haskell-beginners] Build setup with dynamic linkining Message-ID: I've removed the static libraries from a machine to save space, and configured cabal to build both libraries and executables dynamically. This works for everything except packages with Custom build-type (e.g. Happy), when cabal-install will try to build setup against the non-existent static libraries. Is there any way to force cabal to build dist/setup dynamically? From toad3k at gmail.com Tue Mar 4 15:21:24 2014 From: toad3k at gmail.com (David McBride) Date: Tue, 4 Mar 2014 10:21:24 -0500 Subject: [Haskell-beginners] Good way of combining functions of type IO (Maybe a) In-Reply-To: References: <53149B4D.3070002@posteo.de> Message-ID: Huh I guess I've been using maybet for so long I never realized it had been added to the transformers library. TIL. On Tue, Mar 4, 2014 at 2:13 AM, Yitzchak Gale wrote: > Nathan H?sken wrote: > >> I want to write a function, which is basically a concatenation of > >> functions of type "IO (Maybe a)". > > David McBride wrote: > > cabal install maybet > > I would recommend using the standard MaybeT > type, from the transformers library that is > part of the Haskell Platform, unless you have > a special reason to use a different library > from Hackage. > > David's code works fine with the transformers library, > after a slight modification of the import: > > import Control.Monad.Trans.Maybe > > Also - using the MaybeT monad is not the only > way to do this. Maybe comes with a whole > collection of very convenient combinators like > "maybe", "fromMaybe", etc. So you can also do > the calculation entirely in just IO without > very much extra noice. Choose the approach > that works out nicest for your particular > application. > > Here is David's code, modified to do the > calculations directly in the IO monad: > > f1 :: IO (Maybe Int) > f1 = return . Just $ 1 > > d2 :: Int -> IO (Maybe String) > d2 = return . Just . show > > blah :: IO (Maybe (Int, String)) > blah = do > a <- f1 > b <- maybe (return Nothing) d2 a > return (a,b) > > If you end up using things like > "maybe (return Nothing)" and > "fromMaybe (return Nothing)" a lot, > you can define aliases for them. > Perhaps there ought to be aliases like > that in the standard libraries somewhere... > > Regards, > Yitz > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nathan.huesken at posteo.de Wed Mar 5 13:53:22 2014 From: nathan.huesken at posteo.de (=?ISO-8859-1?Q?Nathan_H=FCsken?=) Date: Wed, 05 Mar 2014 14:53:22 +0100 Subject: [Haskell-beginners] Combining IO and Either function to "EitherT e IO a" Message-ID: <53172C52.5030005@posteo.de> Hey, I have a function |func1 :: IO String | and another: |func2 :: String -> Either String String | and I want to combine them, giving the output of the first as the input as the second. |func3 :: IO (Either String String) func3 = do tmp <- func1 return (func2 tmp) | Ok, possible. But I rather would like a result of type "EitherT String IO String". So how can I combine these function in a smart way, to get the needed result? Thanks! Nathan -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: OpenPGP digital signature URL: From fuuzetsu at fuuzetsu.co.uk Wed Mar 5 14:31:59 2014 From: fuuzetsu at fuuzetsu.co.uk (Mateusz Kowalczyk) Date: Wed, 05 Mar 2014 14:31:59 +0000 Subject: [Haskell-beginners] Combining IO and Either function to "EitherT e IO a" In-Reply-To: <53172C52.5030005@posteo.de> References: <53172C52.5030005@posteo.de> Message-ID: <5317355F.7010500@fuuzetsu.co.uk> On 05/03/14 13:53, Nathan H?sken wrote: > Hey, > > I have a function > > |func1 :: IO String > | > > and another: > > |func2 :: String -> Either String String > | > > and I want to combine them, giving the output of the first as the input > as the second. > > |func3 :: IO (Either String String) > func3 = do > tmp <- func1 > return (func2 tmp) > | > This is just ?fmap func2 func1? or using the operator, ?func2 <$> func1?. > Ok, possible. But I rather would like a result of type "EitherT String > IO String". > So how can I combine these function in a smart way, to get the needed > result? After using ?func2 <$> func1? we have ?IO (Either String String)? as you point out. The ?EitherT? constructor has type ?m (Either e a)?. Here if m = IO, e = String, a = String so we have exactly what we need: > > :t EitherT $ func2 <$> func1 > EitherT $ func2 <$> func1 :: EitherT String IO String > > Thanks! > Nathan > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -- Mateusz K. From fuuzetsu at fuuzetsu.co.uk Wed Mar 5 14:33:17 2014 From: fuuzetsu at fuuzetsu.co.uk (Mateusz Kowalczyk) Date: Wed, 05 Mar 2014 14:33:17 +0000 Subject: [Haskell-beginners] Combining IO and Either function to "EitherT e IO a" In-Reply-To: <5317355F.7010500@fuuzetsu.co.uk> References: <53172C52.5030005@posteo.de> <5317355F.7010500@fuuzetsu.co.uk> Message-ID: <531735AD.7060301@fuuzetsu.co.uk> On 05/03/14 14:31, Mateusz Kowalczyk wrote: > On 05/03/14 13:53, Nathan H?sken wrote: >> Hey, >> >> I have a function >> >> |func1 :: IO String >> | >> >> and another: >> >> |func2 :: String -> Either String String >> | >> >> and I want to combine them, giving the output of the first as the input >> as the second. >> >> |func3 :: IO (Either String String) >> func3 = do >> tmp <- func1 >> return (func2 tmp) >> | >> > > This is just ?fmap func2 func1? or using the operator, ?func2 <$> func1?. > >> Ok, possible. But I rather would like a result of type "EitherT String >> IO String". >> So how can I combine these function in a smart way, to get the needed >> result? > > After using ?func2 <$> func1? we have ?IO (Either String String)? as you > point out. The ?EitherT? constructor has type ?m (Either e a)?. Oops, that meant to say that it takes a sole argument of that type. > Here if > m = IO, e = String, a = String so we have exactly what we need: > >>> :t EitherT $ func2 <$> func1 >> EitherT $ func2 <$> func1 :: EitherT String IO String > >> >> Thanks! >> Nathan >> >> >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://www.haskell.org/mailman/listinfo/beginners >> > > -- Mateusz K. From ky3 at atamo.com Wed Mar 5 16:45:43 2014 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Wed, 5 Mar 2014 23:45:43 +0700 Subject: [Haskell-beginners] Combining IO and Either function to "EitherT e IO a" In-Reply-To: <53172C52.5030005@posteo.de> References: <53172C52.5030005@posteo.de> Message-ID: On Wed, Mar 5, 2014 at 8:53 PM, Nathan H?sken wrote: > I have a function > > func1 :: IO String > > How is func1 a function? -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From nathan.huesken at posteo.de Wed Mar 5 17:49:32 2014 From: nathan.huesken at posteo.de (=?ISO-8859-1?Q?Nathan_H=FCsken?=) Date: Wed, 05 Mar 2014 18:49:32 +0100 Subject: [Haskell-beginners] Combining IO and Either function to "EitherT e IO a" In-Reply-To: References: <53172C52.5030005@posteo.de> Message-ID: <531763AC.9020606@posteo.de> Mmh, I might not have used haskell terminology correctly. Its a function, in the sense of a function of an imperative language ... Anyhow, the tip from Mateusz worked helped me a lot, thanks for that! On 03/05/2014 05:45 PM, Kim-Ee Yeoh wrote: > > On Wed, Mar 5, 2014 at 8:53 PM, Nathan H?sken > > wrote: > > I have a function > > |func1 :: IO String| > > > How is func1 a function? > > -- Kim-Ee > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From james at jtoll.com Wed Mar 5 18:07:33 2014 From: james at jtoll.com (James Toll) Date: Wed, 5 Mar 2014 12:07:33 -0600 Subject: [Haskell-beginners] Using GHCi, import submodule that needs to import another submodule? Message-ID: Hi, I am trying to figure out how to import one submodule from a hierarchical module in GHCi. For example, at the end of Chapter 6 of LYAHFGG (page 106-107), there's an example of a hierarchical module. Or at the bottom of this page, http://learnyouahaskell.com/modules If I recreate that module on my system and try to import, this is the output: [~/Geometry]$ ls Cube.hs Cuboid.hs Sphere.hs [~/Geometry]$ ghci GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Prelude> import Geometry.Sphere : Could not find module `Geometry.Sphere' It is not a module in the current program, or in any known package. Prelude> :set -iGeometry Prelude> import Geometry.Sphere : Could not find module `Geometry.Sphere' It is not a module in the current program, or in any known package. Prelude> :load Sphere [1 of 1] Compiling Geometry.Sphere ( Sphere.hs, interpreted ) Ok, modules loaded: Geometry.Sphere. *Geometry.Sphere> :load Cube Cube.hs:6:18: Could not find module `Geometry.Cuboid' Use -v to see a list of the files searched for. Failed, modules loaded: none. Prelude> :load Cuboid [1 of 1] Compiling Geometry.Cuboid ( Cuboid.hs, interpreted ) Ok, modules loaded: Geometry.Cuboid. *Geometry.Cuboid> :load Cube Cube.hs:6:18: Could not find module `Geometry.Cuboid' Use -v to see a list of the files searched for. Failed, modules loaded: none. Prelude> So I can't just "import Geometry.Sphere", and I tried setting -i, but that doesn't seem to help. Instead I have to ":load Sphere". Fine, but then when I try to ":load Cube", it fails because of the line in Cube.hs that imports Geometry.Cuboid. Even if I load Geometry.Cuboid first and then try to load Geometry.Cube, it still fails. So, in GHCi, how do I successfully import a submodule that needs to import some other submodule in the module? Thanks, James From daniel.trstenjak at gmail.com Wed Mar 5 18:17:05 2014 From: daniel.trstenjak at gmail.com (Daniel Trstenjak) Date: Wed, 5 Mar 2014 19:17:05 +0100 Subject: [Haskell-beginners] Using GHCi, import submodule that needs to import another submodule? In-Reply-To: References: Message-ID: <20140305181705.GA19433@machine> Hi James, On Wed, Mar 05, 2014 at 12:07:33PM -0600, James Toll wrote: > So, in GHCi, how do I successfully import a submodule that needs to import some other submodule in the module? [~/Geometry]$ cd .. [~]$ ghci > import Geometry.Sphere Greetings, Daniel From ky3 at atamo.com Wed Mar 5 18:18:55 2014 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Thu, 6 Mar 2014 01:18:55 +0700 Subject: [Haskell-beginners] Combining IO and Either function to "EitherT e IO a" In-Reply-To: <531763AC.9020606@posteo.de> References: <53172C52.5030005@posteo.de> <531763AC.9020606@posteo.de> Message-ID: On Thu, Mar 6, 2014 at 12:49 AM, Nathan H?sken wrote: > Mmh, I might not have used haskell terminology correctly. Its a function, > in the sense of a function of an imperative language ... Yes, you could model IO String in C as a function taking void and returning a pointer to char. Calling an IO String a Haskell function would confuse a lot of people. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Wed Mar 5 18:25:48 2014 From: toad3k at gmail.com (David McBride) Date: Wed, 5 Mar 2014 13:25:48 -0500 Subject: [Haskell-beginners] Using GHCi, import submodule that needs to import another submodule? In-Reply-To: References: Message-ID: If you want a source file to have a module Geometry.Cuboid, it should be in a directory named Geometry and the file will have the name of Cuboid.hs. In order to load that you have to start ghci in the directory that contains the Geometry directory, not in the one that contains the source file. So cd .., ghci Geometry/Cuboid.hs On Wed, Mar 5, 2014 at 1:07 PM, James Toll wrote: > Hi, > > I am trying to figure out how to import one submodule from a hierarchical > module in GHCi. For example, at the end of Chapter 6 of LYAHFGG (page > 106-107), there's an example of a hierarchical module. Or at the bottom of > this page, http://learnyouahaskell.com/modules > > If I recreate that module on my system and try to import, this is the > output: > > [~/Geometry]$ ls > Cube.hs Cuboid.hs Sphere.hs > [~/Geometry]$ ghci > GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help > Loading package ghc-prim ... linking ... done. > Loading package integer-gmp ... linking ... done. > Loading package base ... linking ... done. > Prelude> import Geometry.Sphere > > : > Could not find module `Geometry.Sphere' > It is not a module in the current program, or in any known package. > Prelude> :set -iGeometry > Prelude> import Geometry.Sphere > > : > Could not find module `Geometry.Sphere' > It is not a module in the current program, or in any known package. > Prelude> :load Sphere > [1 of 1] Compiling Geometry.Sphere ( Sphere.hs, interpreted ) > Ok, modules loaded: Geometry.Sphere. > *Geometry.Sphere> :load Cube > > Cube.hs:6:18: > Could not find module `Geometry.Cuboid' > Use -v to see a list of the files searched for. > Failed, modules loaded: none. > Prelude> :load Cuboid > [1 of 1] Compiling Geometry.Cuboid ( Cuboid.hs, interpreted ) > Ok, modules loaded: Geometry.Cuboid. > *Geometry.Cuboid> :load Cube > > Cube.hs:6:18: > Could not find module `Geometry.Cuboid' > Use -v to see a list of the files searched for. > Failed, modules loaded: none. > Prelude> > > > So I can't just "import Geometry.Sphere", and I tried setting -i, but that > doesn't seem to help. Instead I have to ":load Sphere". Fine, but then > when I try to ":load Cube", it fails because of the line in Cube.hs that > imports Geometry.Cuboid. Even if I load Geometry.Cuboid first and then try > to load Geometry.Cube, it still fails. > > So, in GHCi, how do I successfully import a submodule that needs to import > some other submodule in the module? > > Thanks, > > > James > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From james at jtoll.com Wed Mar 5 18:39:01 2014 From: james at jtoll.com (James Toll) Date: Wed, 5 Mar 2014 12:39:01 -0600 Subject: [Haskell-beginners] Using GHCi, import submodule that needs to import another submodule? In-Reply-To: <20140305181705.GA19433@machine> References: <20140305181705.GA19433@machine> Message-ID: On Mar 5, 2014, at 12:17 PM, Daniel Trstenjak wrote: > Hi James, > > On Wed, Mar 05, 2014 at 12:07:33PM -0600, James Toll wrote: >> So, in GHCi, how do I successfully import a submodule that needs to import some other submodule in the module? > > [~/Geometry]$ cd .. > [~]$ ghci >> import Geometry.Sphere Hi Daniel, Thank you for your suggestion. It appears that your suggestion partially works. Picking up from where I left off previously: Prelude> :q Leaving GHCi. [~/Geometry]$ cd .. [~/]$ ls Geometry/ clang-xcode5-wrapper.hs test.hs [~/]$ ghci GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Prelude> import Geometry.Sphere : Could not find module `Geometry.Sphere' It is not a module in the current program, or in any known package. Prelude> :load Sphere : Could not find module `Sphere' Use -v to see a list of the files searched for. Failed, modules loaded: none. Prelude> :load Geometry.Sphere [1 of 1] Compiling Geometry.Sphere ( Geometry/Sphere.hs, interpreted ) Ok, modules loaded: Geometry.Sphere. *Geometry.Sphere> :load Geometry.Cube [1 of 2] Compiling Geometry.Cuboid ( Geometry/Cuboid.hs, interpreted ) [2 of 2] Compiling Geometry.Cube ( Geometry/Cube.hs, interpreted ) Ok, modules loaded: Geometry.Cube, Geometry.Cuboid. *Geometry.Cube> So import still does not work. But by trying ?:load" from the parent directory, I was able to load Sphere, Cube and Cuboid. The problem is that it appears that only one is available at a time (i.e. loading Cube displaces Sphere). What?s more there is no way to do qualified imports. Regards, James From byorgey at seas.upenn.edu Wed Mar 5 18:47:48 2014 From: byorgey at seas.upenn.edu (Brent Yorgey) Date: Wed, 5 Mar 2014 13:47:48 -0500 Subject: [Haskell-beginners] Using GHCi, import submodule that needs to import another submodule? In-Reply-To: References: <20140305181705.GA19433@machine> Message-ID: <20140305184748.GA12237@seas.upenn.edu> On Wed, Mar 05, 2014 at 12:39:01PM -0600, James Toll wrote: > Prelude> :load Geometry.Sphere > [1 of 1] Compiling Geometry.Sphere ( Geometry/Sphere.hs, interpreted ) > Ok, modules loaded: Geometry.Sphere. > *Geometry.Sphere> :load Geometry.Cube > [1 of 2] Compiling Geometry.Cuboid ( Geometry/Cuboid.hs, interpreted ) > [2 of 2] Compiling Geometry.Cube ( Geometry/Cube.hs, interpreted ) > Ok, modules loaded: Geometry.Cube, Geometry.Cuboid. > *Geometry.Cube> Use :add instead of :load for Geometry.Cube. :load loads the specified module but forgets anything that was previously loaded. :add loads a module without forgetting previously loaded things. The differeces between :load, :add, and :module/import are somewhat subtle and certainly confusing. You may find http://www.haskell.org/ghc/docs/7.6.3/html/users_guide/interactive-evaluation.html#ghci-scope helpful. -Brent From james at jtoll.com Wed Mar 5 19:12:33 2014 From: james at jtoll.com (James Toll) Date: Wed, 5 Mar 2014 13:12:33 -0600 Subject: [Haskell-beginners] Using GHCi, import submodule that needs to import another submodule? In-Reply-To: <20140305184748.GA12237@seas.upenn.edu> References: <20140305181705.GA19433@machine> <20140305184748.GA12237@seas.upenn.edu> Message-ID: On Mar 5, 2014, at 12:47 PM, Brent Yorgey wrote: > On Wed, Mar 05, 2014 at 12:39:01PM -0600, James Toll wrote: >> Prelude> :load Geometry.Sphere >> [1 of 1] Compiling Geometry.Sphere ( Geometry/Sphere.hs, interpreted ) >> Ok, modules loaded: Geometry.Sphere. >> *Geometry.Sphere> :load Geometry.Cube >> [1 of 2] Compiling Geometry.Cuboid ( Geometry/Cuboid.hs, interpreted ) >> [2 of 2] Compiling Geometry.Cube ( Geometry/Cube.hs, interpreted ) >> Ok, modules loaded: Geometry.Cube, Geometry.Cuboid. >> *Geometry.Cube> > > Use :add instead of :load for Geometry.Cube. :load loads the > specified module but forgets anything that was previously loaded. > :add loads a module without forgetting previously loaded things. > > The differeces between :load, :add, and :module/import are somewhat > subtle and certainly confusing. You may find > > http://www.haskell.org/ghc/docs/7.6.3/html/users_guide/interactive-evaluation.html#ghci-scope Thank you for the suggestion. I will read up on scope and try using add. But what I would really prefer is to be able to import individual submodules in GHCi using standard import syntax from the GHCi command line: Prelude> import qualified Geometry.Sphere as Sphere Is that not possible? LYAHFFG seems to imply that it is, and Daniel?s response to this question seems to also suggest that it?s possible. Then I can control how the functions in the submodule are referenced. Thanks again, James From daniel.trstenjak at gmail.com Wed Mar 5 19:18:36 2014 From: daniel.trstenjak at gmail.com (Daniel Trstenjak) Date: Wed, 5 Mar 2014 20:18:36 +0100 Subject: [Haskell-beginners] Using GHCi, import submodule that needs to import another submodule? In-Reply-To: References: <20140305181705.GA19433@machine> Message-ID: <20140305191836.GA23005@machine> Hi James, > So import still does not work. But by trying ?:load" from the parent > directory, I was able to load Sphere, Cube and Cuboid. The problem is > that it appears that only one is available at a time (i.e. loading > Cube displaces Sphere). What?s more there is no way to do qualified > imports. Sorry about this one. 'import' depends on the available/installed ghc packages, the given module name 'Geometry.Sphere' is looked up in these packages. Calling 'ghc-pkg list' will give you a list of all packages. If you don't have created and installed a package for your geometry files, then ghci will not know them. So calling ':load/:add' is the right thing here. Greetings, Daniel From james at jtoll.com Wed Mar 5 21:11:06 2014 From: james at jtoll.com (James Toll) Date: Wed, 5 Mar 2014 15:11:06 -0600 Subject: [Haskell-beginners] Using GHCi, import submodule that needs to import another submodule? In-Reply-To: <20140305191836.GA23005@machine> References: <20140305181705.GA19433@machine> <20140305191836.GA23005@machine> Message-ID: <807D94D7-793F-4683-A6D5-16542D972ADB@jtoll.com> On Mar 5, 2014, at 1:18 PM, Daniel Trstenjak wrote: > Hi James, > >> So import still does not work. But by trying ?:load" from the parent >> directory, I was able to load Sphere, Cube and Cuboid. The problem is >> that it appears that only one is available at a time (i.e. loading >> Cube displaces Sphere). What?s more there is no way to do qualified >> imports. > > Sorry about this one. 'import' depends on the available/installed ghc packages, > the given module name 'Geometry.Sphere' is looked up in these packages. > > Calling 'ghc-pkg list' will give you a list of all packages. > > If you don't have created and installed a package for your geometry > files, then ghci will not know them. > > So calling ':load/:add' is the right thing here. Daniel et al., Thank you for the clarification. No worries. I appreciate you taking the time to respond to my question. One observation I could make as a beginner is that I wish the documentation made a better distinction between packages and modules. I suppose the ambiguity from my standpoint (please correct me if I?m wrong) is that all packages are, or include, modules, but not all modules are packages. As such, import would only be used for installed packages and not for my own modules. But the documentation for import routinely makes reference to modules, leading myself to incorrectly believe that I could import my own local modules using import. I?ve been reading through the page regarding scope that Brent referenced and feel as though it has clarified a few things, but also raised many more questions. Unfortunately it doesn?t make a clear distinction between packages and modules either. From http://www.haskell.org/ghc/docs/7.6.3/html/users_guide/interactive-evaluation.html#ghci-scope 2.4.5.1. :module and :load I?d love to get a clear definition of ?loaded" vs "in scope". Does import only bring a module into scope, not load it? Then would installed packages be considered loaded but not in scope? But they don?t show up with :show modules. Would using import then place them in scope? My personal modules would be neither loaded, nor in scope? Using :load loads them and also places them in scope? Using :modules -m would remove a module from scope but it would still be loaded? Lots and lots of questions. If anyone has any links to documentation that would clear up some of these questions, I?d appreciate it. Anyway, it appears that using import is not possible for my modules, only for installed packages, so using :load and :add are the correct solution. Thanks again for the help, James From tim.v2.0 at gmail.com Wed Mar 5 23:19:48 2014 From: tim.v2.0 at gmail.com (Tim Perry) Date: Wed, 5 Mar 2014 15:19:48 -0800 Subject: [Haskell-beginners] Combining IO and Either function to "EitherT e IO a" In-Reply-To: References: <53172C52.5030005@posteo.de> <531763AC.9020606@posteo.de> Message-ID: Kim-Ee, If I see a function with the signature ":: IO String" I immediately assume it is getLine or one of its ilk. Thus the Op's question doesn't seem odd at all to me. Could you explicate on why you find this very confusing? After all: :Prelude> :t getLine getLine :: IO String I think you know a lot more about Haskell than I do so I'm curious what the thinking behind your post was. Thanks, Tim On Wed, Mar 5, 2014 at 10:18 AM, Kim-Ee Yeoh wrote: > > On Thu, Mar 6, 2014 at 12:49 AM, Nathan H?sken wrote: > >> Mmh, I might not have used haskell terminology correctly. Its a function, >> in the sense of a function of an imperative language ... > > > Yes, you could model IO String in C as a function taking void and > returning a pointer to char. > > Calling an IO String a Haskell function would confuse a lot of people. > > -- Kim-Ee > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From davidleothomas at gmail.com Wed Mar 5 23:22:39 2014 From: davidleothomas at gmail.com (David Thomas) Date: Wed, 5 Mar 2014 15:22:39 -0800 Subject: [Haskell-beginners] Combining IO and Either function to "EitherT e IO a" In-Reply-To: References: <53172C52.5030005@posteo.de> <531763AC.9020606@posteo.de> Message-ID: It's a function of zero arguments. It's also sort of, kind of a function from RealWorld to (String, RealWorld) if you squint. On Wed, Mar 5, 2014 at 10:18 AM, Kim-Ee Yeoh wrote: > > On Thu, Mar 6, 2014 at 12:49 AM, Nathan H?sken wrote: > >> Mmh, I might not have used haskell terminology correctly. Its a function, >> in the sense of a function of an imperative language ... > > > Yes, you could model IO String in C as a function taking void and > returning a pointer to char. > > Calling an IO String a Haskell function would confuse a lot of people. > > -- Kim-Ee > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From byorgey at seas.upenn.edu Wed Mar 5 23:31:07 2014 From: byorgey at seas.upenn.edu (Brent Yorgey) Date: Wed, 5 Mar 2014 18:31:07 -0500 Subject: [Haskell-beginners] Combining IO and Either function to "EitherT e IO a" In-Reply-To: References: <53172C52.5030005@posteo.de> <531763AC.9020606@posteo.de> Message-ID: <20140305233107.GA20579@seas.upenn.edu> In Haskell, the term "function" is reserved for things whose types include an arrow, ->. IO String has no -> in it, therefore it is not a function. Instead we might call it an "action" or a "procedure". -Brent On Wed, Mar 05, 2014 at 03:19:48PM -0800, Tim Perry wrote: > Kim-Ee, > > If I see a function with the signature ":: IO String" I immediately assume > it is getLine or one of its ilk. Thus the Op's question doesn't seem odd at > all to me. Could you explicate on why you find this very confusing? After > all: > > :Prelude> :t getLine > getLine :: IO String > > I think you know a lot more about Haskell than I do so I'm curious what the > thinking behind your post was. > > > Thanks, > > Tim > > > On Wed, Mar 5, 2014 at 10:18 AM, Kim-Ee Yeoh wrote: > > > > > On Thu, Mar 6, 2014 at 12:49 AM, Nathan H?sken wrote: > > > >> Mmh, I might not have used haskell terminology correctly. Its a function, > >> in the sense of a function of an imperative language ... > > > > > > Yes, you could model IO String in C as a function taking void and > > returning a pointer to char. > > > > Calling an IO String a Haskell function would confuse a lot of people. > > > > -- Kim-Ee > > > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://www.haskell.org/mailman/listinfo/beginners > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners From byorgey at seas.upenn.edu Wed Mar 5 23:35:54 2014 From: byorgey at seas.upenn.edu (Brent Yorgey) Date: Wed, 5 Mar 2014 18:35:54 -0500 Subject: [Haskell-beginners] Combining IO and Either function to "EitherT e IO a" In-Reply-To: References: <53172C52.5030005@posteo.de> <531763AC.9020606@posteo.de> Message-ID: <20140305233554.GB20579@seas.upenn.edu> On Wed, Mar 05, 2014 at 03:22:39PM -0800, David Thomas wrote: > It's a function of zero arguments. This is really stretching the meaning of the word "function" beyond any reasonable, useful definition, in my opinion. See the discussion here: http://conal.net/blog/posts/everything-is-a-function-in-haskell A much more useful (and precise) point of view is that in Haskell, all functions take exactly one argument. Under that view, of course, there is no such thing as a function of zero arguments. > It's also sort of, kind of a function > from RealWorld to (String, RealWorld) if you squint. I'm don't think this is a very helpful way to understand IO, though it is probably closer to the sense in which the OP understood IO String to be a function. My guess is that what is really going on here is a confusion of terminology from imperative languages, some of which use the word "function" for everything, whether they take any arguments or not, return any values or not, have any side effects or not, etc. -Brent > On Wed, Mar 5, 2014 at 10:18 AM, Kim-Ee Yeoh wrote: > > > > > On Thu, Mar 6, 2014 at 12:49 AM, Nathan H?sken wrote: > > > >> Mmh, I might not have used haskell terminology correctly. Its a function, > >> in the sense of a function of an imperative language ... > > > > > > Yes, you could model IO String in C as a function taking void and > > returning a pointer to char. > > > > Calling an IO String a Haskell function would confuse a lot of people. > > > > -- Kim-Ee > > > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://www.haskell.org/mailman/listinfo/beginners > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners From davidleothomas at gmail.com Wed Mar 5 23:38:45 2014 From: davidleothomas at gmail.com (David Thomas) Date: Wed, 5 Mar 2014 15:38:45 -0800 Subject: [Haskell-beginners] Combining IO and Either function to "EitherT e IO a" In-Reply-To: <20140305233554.GB20579@seas.upenn.edu> References: <53172C52.5030005@posteo.de> <531763AC.9020606@posteo.de> <20140305233554.GB20579@seas.upenn.edu> Message-ID: Agreed on all counts. On Wed, Mar 5, 2014 at 3:35 PM, Brent Yorgey wrote: > On Wed, Mar 05, 2014 at 03:22:39PM -0800, David Thomas wrote: > > It's a function of zero arguments. > > This is really stretching the meaning of the word "function" beyond > any reasonable, useful definition, in my opinion. See the discussion > here: > > http://conal.net/blog/posts/everything-is-a-function-in-haskell > > A much more useful (and precise) point of view is that in Haskell, all > functions take exactly one argument. Under that view, of course, > there is no such thing as a function of zero arguments. > > > It's also sort of, kind of a function > > from RealWorld to (String, RealWorld) if you squint. > > I'm don't think this is a very helpful way to understand IO, though it > is probably closer to the sense in which the OP understood IO String > to be a function. > > My guess is that what is really going on here is a confusion of > terminology from imperative languages, some of which use the word > "function" for everything, whether they take any arguments or not, > return any values or not, have any side effects or not, etc. > > -Brent > > > On Wed, Mar 5, 2014 at 10:18 AM, Kim-Ee Yeoh wrote: > > > > > > > > On Thu, Mar 6, 2014 at 12:49 AM, Nathan H?sken < > nathan.huesken at posteo.de>wrote: > > > > > >> Mmh, I might not have used haskell terminology correctly. Its a > function, > > >> in the sense of a function of an imperative language ... > > > > > > > > > Yes, you could model IO String in C as a function taking void and > > > returning a pointer to char. > > > > > > Calling an IO String a Haskell function would confuse a lot of people. > > > > > > -- Kim-Ee > > > > > > _______________________________________________ > > > Beginners mailing list > > > Beginners at haskell.org > > > http://www.haskell.org/mailman/listinfo/beginners > > > > > > > > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://www.haskell.org/mailman/listinfo/beginners > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From daniel.trstenjak at gmail.com Thu Mar 6 10:06:36 2014 From: daniel.trstenjak at gmail.com (Daniel Trstenjak) Date: Thu, 6 Mar 2014 11:06:36 +0100 Subject: [Haskell-beginners] Using GHCi, import submodule that needs to import another submodule? In-Reply-To: <807D94D7-793F-4683-A6D5-16542D972ADB@jtoll.com> References: <20140305181705.GA19433@machine> <20140305191836.GA23005@machine> <807D94D7-793F-4683-A6D5-16542D972ADB@jtoll.com> Message-ID: <20140306100636.GA3194@machine> Hi James, > One observation I could make as a beginner is that I wish the > documentation made a better distinction between packages and modules. Unfortunately it's even a bit more complex. First of all there're the cabal packages which contain your haskell source files which define the modules. These cabal packages are build and installed by cabal and result into ghc packages, which are some kind of binary blob (I don't know the details) that contains all your modules in a compiled form, and these packages are readable by ghc/ghci. So 'import' refers to the modules of the ghc packages and ':load' refers to the modules in the source files. > 2.4.5.1. :module and :load I?d love to get a clear definition of ?loaded" vs "in scope". ':load' is pretty much the same as loading a package and importing a module from it, so ':load' does both at once. Everything that's imported is in scope. > Does import only bring a module into scope, not load it? You've to load something before you can bring it with import into scope. > Then would installed packages be considered loaded but not in scope? I think that ghci only loads and imports the packages defining the Prelude module at startup. All other packages are loaded lazily if you're importing a module of them. > Using :load loads them and also places them in scope? Yes. > Using :modules -m would remove a module from scope but it would still be loaded? I think so for ghc package modules, but I'm not sure for modules loaded with ':load', they might get unloaded again, but even if not, I don't think that you could get them back in scope by using 'import'. Greetings, Daniel From tim.v2.0 at gmail.com Thu Mar 6 17:21:29 2014 From: tim.v2.0 at gmail.com (Tim Perry) Date: Thu, 6 Mar 2014 09:21:29 -0800 Subject: [Haskell-beginners] Combining IO and Either function to "EitherT e IO a" In-Reply-To: References: <53172C52.5030005@posteo.de> <531763AC.9020606@posteo.de> <20140305233554.GB20579@seas.upenn.edu> Message-ID: Thanks Brent. Your posts and the link helped. On Wed, Mar 5, 2014 at 3:38 PM, David Thomas wrote: > Agreed on all counts. > > > On Wed, Mar 5, 2014 at 3:35 PM, Brent Yorgey wrote: > >> On Wed, Mar 05, 2014 at 03:22:39PM -0800, David Thomas wrote: >> > It's a function of zero arguments. >> >> This is really stretching the meaning of the word "function" beyond >> any reasonable, useful definition, in my opinion. See the discussion >> here: >> >> http://conal.net/blog/posts/everything-is-a-function-in-haskell >> >> A much more useful (and precise) point of view is that in Haskell, all >> functions take exactly one argument. Under that view, of course, >> there is no such thing as a function of zero arguments. >> >> > It's also sort of, kind of a function >> > from RealWorld to (String, RealWorld) if you squint. >> >> I'm don't think this is a very helpful way to understand IO, though it >> is probably closer to the sense in which the OP understood IO String >> to be a function. >> >> My guess is that what is really going on here is a confusion of >> terminology from imperative languages, some of which use the word >> "function" for everything, whether they take any arguments or not, >> return any values or not, have any side effects or not, etc. >> >> -Brent >> >> > On Wed, Mar 5, 2014 at 10:18 AM, Kim-Ee Yeoh wrote: >> > >> > > >> > > On Thu, Mar 6, 2014 at 12:49 AM, Nathan H?sken < >> nathan.huesken at posteo.de>wrote: >> > > >> > >> Mmh, I might not have used haskell terminology correctly. Its a >> function, >> > >> in the sense of a function of an imperative language ... >> > > >> > > >> > > Yes, you could model IO String in C as a function taking void and >> > > returning a pointer to char. >> > > >> > > Calling an IO String a Haskell function would confuse a lot of people. >> > > >> > > -- Kim-Ee >> > > >> > > _______________________________________________ >> > > Beginners mailing list >> > > Beginners at haskell.org >> > > http://www.haskell.org/mailman/listinfo/beginners >> > > >> > > >> >> > _______________________________________________ >> > Beginners mailing list >> > Beginners at haskell.org >> > http://www.haskell.org/mailman/listinfo/beginners >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://www.haskell.org/mailman/listinfo/beginners >> > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From james at jtoll.com Fri Mar 7 03:06:23 2014 From: james at jtoll.com (James Toll) Date: Thu, 6 Mar 2014 21:06:23 -0600 Subject: [Haskell-beginners] Using GHCi, import submodule that needs to import another submodule? In-Reply-To: <20140306100636.GA3194@machine> References: <20140305181705.GA19433@machine> <20140305191836.GA23005@machine> <807D94D7-793F-4683-A6D5-16542D972ADB@jtoll.com> <20140306100636.GA3194@machine> Message-ID: <99619C13-2D69-4B6E-BCAD-7130126174B0@jtoll.com> On Mar 6, 2014, at 4:06 AM, Daniel Trstenjak wrote: > > Hi James, > >> One observation I could make as a beginner is that I wish the >> documentation made a better distinction between packages and modules. > > Unfortunately it's even a bit more complex. Daniel, Thanks for answering some of my many questions. I really appreciate your taking the time. I clearly still have a lot to learn on the subject but I appreciate the help. Thanks, James From derek.mcloughlin at gmail.com Mon Mar 10 12:59:04 2014 From: derek.mcloughlin at gmail.com (Derek McLoughlin) Date: Mon, 10 Mar 2014 12:59:04 +0000 Subject: [Haskell-beginners] MultiParamTypeClasses confusion Message-ID: Hi, In Chapter 6 of "Beginning Haskell" by Apress there's a couple of classes introduced for vectors and things that can be vectorized (not related to Data.Vector) {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} class Vector v where distance :: v -> v -> Double instance Vector (Double, Double) where distance (a,b) (c,d) = sqrt $ (c - a) * (c - a) + (d - b) * (d - b) class Vectorizable e v where toVector :: e -> v instance Vectorizable (Double, Double) (Double, Double) where toVector = id x = 1.0 :: Double y = 10.0 :: Double While I understand how to use the "distance" function: ghci> distance (x, x) (y, y) 12.727922061357855 ... and I can see how "toVector" is used in their code ghci> distance (x, x) $ toVector (y, y) 12.727922061357855 I don't understand why this doesn't work: ghci> let z = toVector (y, y) interactive>:32:9: No instance for (Vectorizable (Double, Double) v0) arising from a use of `toVector' The type variable `v0' is ambiguous Possible fix: add a type signature that fixes these type variable(s) Note: there is a potential instance available: instance Vectorizable (Double, Double) (Double, Double) -- Defined at vector.hs:13:10 Possible fix: add an instance declaration for (Vectorizable (Double, Double) v0) In the expression: toVector (y, y) In an equation for `z': z = toVector (y, y) It seems odd that "toVector" works when used as an argument to "distance" but not when used in a let expression. Can anyone explain? Derek. From allbery.b at gmail.com Mon Mar 10 13:12:13 2014 From: allbery.b at gmail.com (Brandon Allbery) Date: Mon, 10 Mar 2014 09:12:13 -0400 Subject: [Haskell-beginners] MultiParamTypeClasses confusion In-Reply-To: References: Message-ID: On Mon, Mar 10, 2014 at 8:59 AM, Derek McLoughlin < derek.mcloughlin at gmail.com> wrote: > ghci> distance (x, x) $ toVector (y, y) > 12.727922061357855 > > I don't understand why this doesn't work: > > ghci> let z = toVector (y, y) > interactive>:32:9: > No instance for (Vectorizable (Double, Double) v0) > arising from a use of `toVector' > The type variable `v0' is ambiguous > Possible fix: add a type signature that fixes these type variable(s) > Note: there is a potential instance available: > instance Vectorizable (Double, Double) (Double, Double) > -- Defined at vector.hs:13:10 > Possible fix: > add an instance declaration for (Vectorizable (Double, Double) v0) > In the expression: toVector (y, y) > In an equation for `z': z = toVector (y, y) > > It seems odd that "toVector" works when used as an argument to > "distance" but not when used in a let expression. > > Can anyone explain? > When you use them together, Haskell can infer the correct type for `v0` from the inferred type of `distance` by applying defaulting: the type of `sqrt` introduces a constraint that is subject to defaulting. If you separate them, it can no longer determine a concrete type for your `let`, as multiparameter type classes are not subject to defaulting (and can't be). Also, Haskell cannot conclude from the existence of a single possible instance that it should use that instance: the meaning of your expression would then change if you imported a module which defined a new instance. The requirement for a concrete type comes from the monomorphism restriction, which is applied to your `let` because `z` has no parameters. http://www.haskell.org/haskellwiki/Monomorphism_restriction Many people turn off the monomorphism restriction in ghci to avoid this kind of issue. :set -XNoMonomoprhismRestriction which you can put in ~/.ghci so that it is the default for new ghci sessions. -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From derek.mcloughlin at gmail.com Mon Mar 10 13:21:52 2014 From: derek.mcloughlin at gmail.com (Derek McLoughlin) Date: Mon, 10 Mar 2014 13:21:52 +0000 Subject: [Haskell-beginners] MultiParamTypeClasses confusion In-Reply-To: References: Message-ID: Thanks for that. I see that I can now use: ghci> let z = toVector (y, y) :: (Double, Double) ghci> z (10.0,10.0) On 10 March 2014 13:12, Brandon Allbery wrote: > On Mon, Mar 10, 2014 at 8:59 AM, Derek McLoughlin > wrote: >> >> ghci> distance (x, x) $ toVector (y, y) >> 12.727922061357855 >> >> I don't understand why this doesn't work: >> >> ghci> let z = toVector (y, y) >> interactive>:32:9: >> No instance for (Vectorizable (Double, Double) v0) >> arising from a use of `toVector' >> The type variable `v0' is ambiguous >> Possible fix: add a type signature that fixes these type variable(s) >> Note: there is a potential instance available: >> instance Vectorizable (Double, Double) (Double, Double) >> -- Defined at vector.hs:13:10 >> Possible fix: >> add an instance declaration for (Vectorizable (Double, Double) v0) >> In the expression: toVector (y, y) >> In an equation for `z': z = toVector (y, y) >> >> It seems odd that "toVector" works when used as an argument to >> "distance" but not when used in a let expression. >> >> Can anyone explain? > > > When you use them together, Haskell can infer the correct type for `v0` from > the inferred type of `distance` by applying defaulting: the type of `sqrt` > introduces a constraint that is subject to defaulting. If you separate them, > it can no longer determine a concrete type for your `let`, as multiparameter > type classes are not subject to defaulting (and can't be). Also, Haskell > cannot conclude from the existence of a single possible instance that it > should use that instance: the meaning of your expression would then change > if you imported a module which defined a new instance. > > The requirement for a concrete type comes from the monomorphism restriction, > which is applied to your `let` because `z` has no parameters. > > http://www.haskell.org/haskellwiki/Monomorphism_restriction > > Many people turn off the monomorphism restriction in ghci to avoid this kind > of issue. > > :set -XNoMonomoprhismRestriction > > which you can put in ~/.ghci so that it is the default for new ghci > sessions. > > -- > brandon s allbery kf8nh sine nomine associates > allbery.b at gmail.com ballbery at sinenomine.net > unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > From ky3 at atamo.com Tue Mar 11 10:04:37 2014 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Tue, 11 Mar 2014 17:04:37 +0700 Subject: [Haskell-beginners] Questions too basic for this mailing list? Message-ID: One of the attributes of the haskell community that I take pride in is the balance between democracy and upholding standards. High technical standards such as correctness, ease-of-reasoning, brevity are valued, as well as high community standards such as humor, empathy, addressing the other with dignity. All the above, coupled with an openness to the world-at-large, is the kit and kaboodle of the accidental haskeller. So when the response to a newcomer boils down to "take your basic questions elsewhere", I wonder about these values and I wonder about the community's openness. I for one regret losing the opportunity of exploring very interesting questions about syntax, even elementary syntax, a common obstacle faced by many. Consider how Haskell syntax was designed in a rare confluence of events requiring tremendous buy-in (and patience, and empathy, and openness) from a superficially similar but actually a very diverse group with vigorous, opposing opinions. In an environment that turns inimical to such basic, foundational values -- whither progress? I feel the loss deeply. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From james at jtoll.com Wed Mar 12 00:51:23 2014 From: james at jtoll.com (James Toll) Date: Tue, 11 Mar 2014 19:51:23 -0500 Subject: [Haskell-beginners] library for lattice data structure Message-ID: <8E8682C9-5413-44F3-A6C2-B9E46C9CEF82@jtoll.com> Hi, I have a general question regarding data structures, maybe functional data structures, in Haskell and I?m hoping for some advice. I would like to implement the binomial option pricing model in Haskell. https://en.wikipedia.org/wiki/Binomial_options_pricing_model Given its lattice structure, I originally thought of trying a recursive implementation, but because it?s recombining, the interior nodes would be calculated twice. Although the implementation might be elegant, it doesn?t seem inefficient. Therefore I?ve been searching through Hackage for a data structure library that might lend itself to this problem. There are a ton of libraries and as I don?t have any experience with them, I was hoping someone could provide some advice to narrow the field. Some of the packages I've found so far are: lattices package http://hackage.haskell.org/package/lattices From the name I thought this might be perfect, but the documentation is very terse and there doesn?t appear to be any other documentation so I?m not even sure how to get started with constructing a lattice with this package. matrix package https://hackage.haskell.org/package/matrix This package seems fairly straightforward, and a matrix would work (it?s probably what I would use in R), but it doesn?t seem ideal. There are other more sophisticated packages with matrices like hmatrix and repa but they seem like overkill unless this package is just slow. vector package https://hackage.haskell.org/package/vector Vectors might also work for a data structure, but a matrix just seems like it would be easier. I thought this example implementation in Haskell was intriguing but it doesn?t sound as though it?s very quick. http://www.thulasidas.com/2009-03/a-new-kind-of-binomial-tree.htm Any advice on an appropriate data structure in Haskell for the problem? The solution doesn?t necessarily have to include a package. Thanks James From byorgey at seas.upenn.edu Wed Mar 12 01:40:47 2014 From: byorgey at seas.upenn.edu (Brent Yorgey) Date: Tue, 11 Mar 2014 21:40:47 -0400 Subject: [Haskell-beginners] library for lattice data structure In-Reply-To: <8E8682C9-5413-44F3-A6C2-B9E46C9CEF82@jtoll.com> References: <8E8682C9-5413-44F3-A6C2-B9E46C9CEF82@jtoll.com> Message-ID: <20140312014047.GA27144@seas.upenn.edu> Hi James, On Tue, Mar 11, 2014 at 07:51:23PM -0500, James Toll wrote: > Hi, > > I have a general question regarding data structures, maybe functional data structures, in Haskell and I?m hoping for some advice. I would like to implement the binomial option pricing model in Haskell. > > https://en.wikipedia.org/wiki/Binomial_options_pricing_model > > Given its lattice structure, I originally thought of trying a > recursive implementation, but because it?s recombining, the interior > nodes would be calculated twice. It's even worse than that---a naive implementation will end up doing exponentially too much work. The interior nodes are recalculated much more than just twice. I once had a student who implemented exactly this, and did it in a clever way---they constructed an actual binary tree data structure, but using some "knot-tying" techniques (http://www.haskell.org/haskellwiki/Tying_the_Knot) to result in all the internal nodes actually being shared in memory. So it really was a binary tree data structure but in memory it looked like a lattice. > lattices package > http://hackage.haskell.org/package/lattices > From the name I thought this might be perfect, but the documentation is very terse and there doesn?t appear to be any other documentation so I?m not even sure how to get started with constructing a lattice with this package. This package is actually about the mathematical abstraction of lattices; it has nothing to do with data structures. Matrices and vectors are definitely too low-level for this problem. > I thought this example implementation in Haskell was intriguing but it doesn?t sound as though it?s very quick. > http://www.thulasidas.com/2009-03/a-new-kind-of-binomial-tree.htm You're right; this implementation has the exponential blowup problem. However, it's actually possible to take this code and make some simple modifications so that it runs quickly, by memoizing the function f. One simple way to do that is to replace the function f with lookups into an array---the trick is that you can construct the array recursively, and thanks to laziness the entries in the array will automatically be computed in the right order, so you don't have to worry about that like you would in, say, R. For an example, see the very last section (titled "Dynamic Programming") on this page: http://www.cis.upenn.edu/~cis194/lectures/06-laziness.html -Brent From ky3 at atamo.com Wed Mar 12 02:57:53 2014 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Wed, 12 Mar 2014 09:57:53 +0700 Subject: [Haskell-beginners] library for lattice data structure In-Reply-To: <8E8682C9-5413-44F3-A6C2-B9E46C9CEF82@jtoll.com> References: <8E8682C9-5413-44F3-A6C2-B9E46C9CEF82@jtoll.com> Message-ID: On Wed, Mar 12, 2014 at 7:51 AM, James Toll wrote: > https://en.wikipedia.org/wiki/Binomial_options_pricing_model > > Given its lattice structure, I originally thought of trying a recursive > implementation, but because it's recombining, the interior nodes would be > calculated twice. Looks like a case of Finite Language Syndrome. 'Lattice' has a pretty specific technical meaning in math, which isn't what's referred to here. If something on hackage mentions lattice, it's invariably the math meaning. This 'lattice' of high finance is a tree data structure, in fact, a special tree you'll probably recognize as Pascal's Triangle. You might want to look up efficient FP representations of the latter. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From james at jtoll.com Wed Mar 12 04:11:31 2014 From: james at jtoll.com (James Toll) Date: Tue, 11 Mar 2014 23:11:31 -0500 Subject: [Haskell-beginners] library for lattice data structure In-Reply-To: <20140312014047.GA27144@seas.upenn.edu> References: <8E8682C9-5413-44F3-A6C2-B9E46C9CEF82@jtoll.com> <20140312014047.GA27144@seas.upenn.edu> Message-ID: On Mar 11, 2014, at 8:40 PM, Brent Yorgey wrote: > I once had a student who implemented exactly this, and did it in a > clever way---they constructed an actual binary tree data structure, > but using some "knot-tying" techniques > (http://www.haskell.org/haskellwiki/Tying_the_Knot) to result in all > the internal nodes actually being shared in memory. So it really was > a binary tree data structure but in memory it looked like a lattice. > >> I thought this example implementation in Haskell was intriguing but it doesn?t sound as though it?s very quick. >> http://www.thulasidas.com/2009-03/a-new-kind-of-binomial-tree.htm > > You're right; this implementation has the exponential blowup problem. > However, it's actually possible to take this code and make some simple > modifications so that it runs quickly, by memoizing the function f. > One simple way to do that is to replace the function f with lookups > into an array---the trick is that you can construct the array > recursively, and thanks to laziness the entries in the array will > automatically be computed in the right order, so you don't have to > worry about that like you would in, say, R. For an example, see the > very last section (titled "Dynamic Programming") on this page: > > http://www.cis.upenn.edu/~cis194/lectures/06-laziness.html > > -Brent Brent, Wow, thank you. I really appreciate your taking the time to provide so much guidance on the subject. I?m vaguely familiar with memoization, but had not even heard of ?knot-tying" techniques. So I?ll really have to look into both topics. Again, thanks for the guidance. As they say, you don?t know what you don?t know, so it?s just so helpful to be pointed in the right direction. Thanks, James From james at jtoll.com Wed Mar 12 04:35:34 2014 From: james at jtoll.com (James Toll) Date: Tue, 11 Mar 2014 23:35:34 -0500 Subject: [Haskell-beginners] library for lattice data structure In-Reply-To: References: <8E8682C9-5413-44F3-A6C2-B9E46C9CEF82@jtoll.com> Message-ID: <5BCBF15A-5D70-4106-AFB7-2BAB790FD4C0@jtoll.com> On Mar 11, 2014, at 9:57 PM, Kim-Ee Yeoh wrote: > Looks like a case of Finite Language Syndrome. 'Lattice' has a pretty specific technical meaning in math, which isn't what's referred to here. If something on hackage mentions lattice, it's invariably the math meaning. Yes, I was concerned there might be some conflict between the finance, math and/or physics terminology. I gave a fair amount of thought to how to refer to the structure, but in the end just picked lattice because that?s how it?s referred to in the wikipedia link I included and because I had already read a lot of quibbling over the use of ?tree?, mostly in the context of binary trees and binary heaps. Coming from a finance background, differences in terminology between finance, physics, math, and statistics is par for the course. I?ll have to be better about understanding the terminology from a math perspective and will try to keep that in mind when posting to this list. Thanks, James From ky3 at atamo.com Wed Mar 12 08:19:31 2014 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Wed, 12 Mar 2014 15:19:31 +0700 Subject: [Haskell-beginners] library for lattice data structure In-Reply-To: <5BCBF15A-5D70-4106-AFB7-2BAB790FD4C0@jtoll.com> References: <8E8682C9-5413-44F3-A6C2-B9E46C9CEF82@jtoll.com> <5BCBF15A-5D70-4106-AFB7-2BAB790FD4C0@jtoll.com> Message-ID: On Wed, Mar 12, 2014 at 11:35 AM, James Toll wrote: > Coming from a finance background, differences in terminology between > finance, physics, math, and statistics is par for the course. I'll have to > be better about understanding the terminology from a math perspective and > will try to keep that in mind when posting to this list. On deeper reflection, I realize it's more complicated than that. Because there are at least two meanings in math. The lattices on hackage are all about posets and meets and joins, tracing back to the work of Birkhoff in that subspecialization of algebra known as order theory. Then there are the lattices in sphere packings and geometric number theory and 'lattice'-based cryptography, cf ntru. One could say that the geometric lattices are closer to binomial lattices, but not really. I wonder why 'binomial tree' isn't perfectly cromulent. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From dbrooks at runforyourlife.org Wed Mar 12 16:09:51 2014 From: dbrooks at runforyourlife.org (Dudley Brooks) Date: Wed, 12 Mar 2014 09:09:51 -0700 Subject: [Haskell-beginners] library for lattice data structure In-Reply-To: References: <8E8682C9-5413-44F3-A6C2-B9E46C9CEF82@jtoll.com> <5BCBF15A-5D70-4106-AFB7-2BAB790FD4C0@jtoll.com> Message-ID: <532086CF.1040708@runforyourlife.org> On 3/12/14 1:19 AM, Kim-Ee Yeoh wrote: > On Wed, Mar 12, 2014 at 11:35 AM, James Toll > wrote: > >> Coming from a finance background, differences in terminology >> between finance, physics, math, and statistics is par for the >> course. I?ll have to be better about understanding the terminology >> from a math perspective and will try to keep that in mind when >> posting to this list. > > On deeper reflection, I realize it's more complicated than that. > Because there are at least two meanings in math. > > The lattices on hackage are all about posets and meets and joins, > tracing back to the work of Birkhoff in that subspecialization of > algebra known as order theory. > > Then there are the lattices in sphere packings and geometric number > theory and 'lattice'-based cryptography, cf ntru. > > One could say that the geometric lattices are closer to binomial > lattices, but not really. I wonder why 'binomial tree' isn't > perfectly cromulent. Thanks. Your comments have embiggened our understanding. -- Dudley From ky3 at atamo.com Wed Mar 12 16:45:50 2014 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Wed, 12 Mar 2014 23:45:50 +0700 Subject: [Haskell-beginners] library for lattice data structure In-Reply-To: <532086CF.1040708@runforyourlife.org> References: <8E8682C9-5413-44F3-A6C2-B9E46C9CEF82@jtoll.com> <5BCBF15A-5D70-4106-AFB7-2BAB790FD4C0@jtoll.com> <532086CF.1040708@runforyourlife.org> Message-ID: On Wed, Mar 12, 2014 at 11:09 PM, Dudley Brooks wrote: > Thanks. Your comments have embiggened our understanding. No Springfield and no bicentennial, but I just realized that I don't know how to represent Pascal's Triangle properly in Haskell -- omg! Google would be cheating. Also boring. So I've self-assigned myself this essay. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From miroslav.karpis at gmail.com Fri Mar 14 20:46:48 2014 From: miroslav.karpis at gmail.com (Miro Karpis) Date: Fri, 14 Mar 2014 21:46:48 +0100 Subject: [Haskell-beginners] scotty + ffi segfault Message-ID: Hi, please can you help me with following? I'm trying to combine scotty + ffi but it returns 'Segmentation fault/access violation in generated code'. The thing is, that when I run only the ffi setmodulestring function, everything works fine. When I call it from scotty I get the segfault. I have hardcoded the 'param' and 'value' parameters in setmodulestring function just to be sure that the input is correct. scotty code: main = scotty 3000 $ do middleware logStdoutDev post "/setstringtest" $ do let param = "FilePath" let value = "C:/dev/misc/haskell/services/FM" result <- liftIO $ FM.setmodulestring param value text "done" ffi code: setmodulestring :: String -> String -> IO CInt setmodulestring param value = do cParam <- newCString param cValue <- newCString value let cParamLength = fromIntegral $ length param ::CInt cValueLength = fromIntegral $ length value ::CInt setVarInArray = (-1)::CInt result <- c_setmodulestring cParam cParamLength cValue cValueLength setVarInArray return result Any comments/ideas more than appreciated. Cheers, Miro -------------- next part -------------- An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Fri Mar 14 20:52:03 2014 From: allbery.b at gmail.com (Brandon Allbery) Date: Fri, 14 Mar 2014 16:52:03 -0400 Subject: [Haskell-beginners] scotty + ffi segfault In-Reply-To: References: Message-ID: On Fri, Mar 14, 2014 at 4:46 PM, Miro Karpis wrote: > setmodulestring :: String -> String -> IO CInt > setmodulestring param value = do > cParam <- newCString param > cValue <- newCString value > let cParamLength = fromIntegral $ length param ::CInt > cValueLength = fromIntegral $ length value ::CInt > setVarInArray = (-1)::CInt > result <- c_setmodulestring cParam cParamLength cValue cValueLength > setVarInArray > return result > The path you show earlier looks like Windows; you probably want CWString for Win32 API functions (so newCWString etc.). -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From miroslav.karpis at gmail.com Fri Mar 14 21:21:52 2014 From: miroslav.karpis at gmail.com (Miro Karpis) Date: Fri, 14 Mar 2014 22:21:52 +0100 Subject: [Haskell-beginners] scotty + ffi segfault In-Reply-To: References: Message-ID: thanks, but also after changing my CString/newCString to CWString/newCWString I'm getting the segfault. As I mentioned if I run the setmodulestring function from ghci everyting works fine (I get proper return value). The problem only comes if I call setmodulestring from the main. I have simplified the main here: main = do let param = "FilePath" let value = "C:/dev/misc/haskell/services/FM" result <- liftIO $ FM.setmodulestring param value return "done" Another strange thing is that I can call another external function from the 'main' function without problem. On Fri, Mar 14, 2014 at 9:52 PM, Brandon Allbery wrote: > On Fri, Mar 14, 2014 at 4:46 PM, Miro Karpis wrote: > >> setmodulestring :: String -> String -> IO CInt >> setmodulestring param value = do >> cParam <- newCString param >> cValue <- newCString value >> let cParamLength = fromIntegral $ length param ::CInt >> cValueLength = fromIntegral $ length value ::CInt >> setVarInArray = (-1)::CInt >> result <- c_setmodulestring cParam cParamLength cValue cValueLength >> setVarInArray >> return result >> > > The path you show earlier looks like Windows; you probably want CWString > for Win32 API functions (so newCWString etc.). > > -- > brandon s allbery kf8nh sine nomine > associates > allbery.b at gmail.com > ballbery at sinenomine.net > unix, openafs, kerberos, infrastructure, xmonad > http://sinenomine.net > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dennis.raddle at gmail.com Sat Mar 15 02:06:36 2014 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Fri, 14 Mar 2014 19:06:36 -0700 Subject: [Haskell-beginners] backtracking search and memory usage Message-ID: I want to implement backtracking search, but I wonder if I'm going to immediately run into memory usage problems if I don't use strict evaluation somewhere. I'm very hazy on how to implement strict evaluation. I'm thinking of creating a generic algorithm that looks something like the following. We have the concept of a data construct that can be built step by step. At each step are choices. We are investigating all the choices and finding series of choices that lead to a completed data construct or "solution." We want to generate a list of all solutions. (My Haskell syntax is rusty so there may be errors in the following.) class Construct a where enumerateChoices :: a -> [b] applyChoice :: a -> b -> a isSolution :: a -> Bool backtrack :: Construct a => a -> [a] backtrack c | isSolution c = [c] | otherwise = concat . map (backtrack . applyChoice c) . enumerateChoices $ c So my question is whether this is going to use a lot of memory to run, maybe by holding all partially solved data? Where would strict evaluation go? -------------- next part -------------- An HTML attachment was scrubbed... URL: From kxra at riseup.net Sat Mar 15 08:52:24 2014 From: kxra at riseup.net (=?UTF-8?B?S+G6j3Jh?=) Date: Sat, 15 Mar 2014 04:52:24 -0400 Subject: [Haskell-beginners] Gnome's FLOSS Outreach Program for Women and Google Summer of Code Opportunities Message-ID: Are there any participating organizations in OPW or GSoC providing opportunities to gain Haskell experience? It would be great to see more Haskell projects participate in this -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuuzetsu at fuuzetsu.co.uk Sat Mar 15 10:16:00 2014 From: fuuzetsu at fuuzetsu.co.uk (Mateusz Kowalczyk) Date: Sat, 15 Mar 2014 10:16:00 +0000 Subject: [Haskell-beginners] Gnome's FLOSS Outreach Program for Women and Google Summer of Code Opportunities In-Reply-To: References: Message-ID: <53242860.7010902@fuuzetsu.co.uk> On 15/03/14 08:52, K?ra wrote: > Are there any participating organizations in OPW or GSoC providing > opportunities to gain Haskell experience? It would be great to see more > Haskell projects participate in this > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > Haskell is part of GSoC this year if that's what you're asking. We're currently at the proposal stage. No idea about OPW. -- Mateusz K. From kxra at riseup.net Sat Mar 15 11:30:15 2014 From: kxra at riseup.net (=?UTF-8?B?S+G6j3Jh?=) Date: Sat, 15 Mar 2014 07:30:15 -0400 Subject: [Haskell-beginners] Gnome's FLOSS Outreach Program for Women and Google Summer of Code Opportunities In-Reply-To: <53242860.7010902@fuuzetsu.co.uk> References: <53242860.7010902@fuuzetsu.co.uk> Message-ID: Oh wow, I didn't see it because i searched for 'haskell' in the tags, not the name of the org! Do you know if they are open to beginners applying? On Sat, Mar 15, 2014 at 6:16 AM, Mateusz Kowalczyk wrote: > On 15/03/14 08:52, K?ra wrote: > > Are there any participating organizations in OPW or GSoC providing > > opportunities to gain Haskell experience? It would be great to see more > > Haskell projects participate in this > > > > > > > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://www.haskell.org/mailman/listinfo/beginners > > > > Haskell is part of GSoC this year if that's what you're asking. We're > currently at the proposal stage. No idea about OPW. > > -- > Mateusz K. > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -- Board of Directors, Free Culture Foundation: www.freeculture.org Campaigns Organizer, Free Software Foundation: www.fsf.org Blog: http://kxra.info - StatusNet Microblog: http://identi.ca/kxra Email: kxra at freeculture.org - SMS: +1.617.340.3661 Jabber/XMPP: kxra at riseup.net - IRC: kxra @freenode @oftc @indymedia -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuuzetsu at fuuzetsu.co.uk Sat Mar 15 11:51:36 2014 From: fuuzetsu at fuuzetsu.co.uk (Mateusz Kowalczyk) Date: Sat, 15 Mar 2014 11:51:36 +0000 Subject: [Haskell-beginners] Gnome's FLOSS Outreach Program for Women and Google Summer of Code Opportunities In-Reply-To: References: <53242860.7010902@fuuzetsu.co.uk> Message-ID: <53243EC8.7030007@fuuzetsu.co.uk> On 15/03/14 11:30, K?ra wrote: > Oh wow, I didn't see it because i searched for 'haskell' in the tags, not > the name of the org! > > Do you know if they are open to beginners applying? > > > On Sat, Mar 15, 2014 at 6:16 AM, Mateusz Kowalczyk > wrote: > >> On 15/03/14 08:52, K?ra wrote: >>> Are there any participating organizations in OPW or GSoC providing >>> opportunities to gain Haskell experience? It would be great to see more >>> Haskell projects participate in this >>> >>> >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://www.haskell.org/mailman/listinfo/beginners >>> >> >> Haskell is part of GSoC this year if that's what you're asking. We're >> currently at the proposal stage. No idea about OPW. >> >> -- >> Mateusz K. >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://www.haskell.org/mailman/listinfo/beginners >> > > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > If you don't know the language to the point where you can write something of benefit to the community then I doubt that your proposal will be accepted, unless it's something really special. There's a section where you list your experience on the proposal template. Basically, if you don't know Haskell at all, it's unlikely that you can come up with a proposal that will be deemed satisfactory and justifying a 3 month project. After all, if someone more experienced can do it in few evenings, it's quite a waste of a slot to accept such a project. If you *do* have a project which would benefit the Haskell community and you think you can complete it in 3 months (and that it's not the case of few evenings for anyone slightly experienced) then please do ask around. It really depends what you mean by ?beginner?. Obviously not only people with 15 years of industrial experience with Haskell are accepted but someone who is only looking to learn the language will probably not do. We have some proposals bouncing around on the haskell-cafe mailing list. There is just over 6 days left for them so if you have a proposal, it's probably worthwhile to get feedback on it ASAP. We also have #haskell-gsoc channel on Freenode where you can ask questions. Hope that clears it up. Please note that I'm not speaking for the whole organisation but merely as an individual. -- Mateusz K. From ky3 at atamo.com Sat Mar 15 16:08:43 2014 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Sat, 15 Mar 2014 23:08:43 +0700 Subject: [Haskell-beginners] backtracking search and memory usage In-Reply-To: References: Message-ID: Let's look at the requirements for this problem, uncovering some of the unspoken ones: 1. very general problem 2. fast, or at least not too slow 3. memory-efficient 4. correct Leaving aside performance issues 2 and 3, is it possible that 1 and 4 alone are enough to deliver plenty of heartburn? I can think of at least one class of problems: the enumeration and application of choices lead to cyclical states. Hence resulting in a list of solutions pockmarked with bottoms. I mean your backtrack function is a correct and succinct description of the very notion of backtracking. The devil is in the details of state design, including the enumeration and application issues I've described. By narrowing the scope of the problem so that you first obtain a library that correctly solves it, you could then focus on performance issues. -- Kim-Ee On Sat, Mar 15, 2014 at 9:06 AM, Dennis Raddle wrote: > I want to implement backtracking search, but I wonder if I'm going to > immediately run into memory usage problems if I don't use strict evaluation > somewhere. I'm very hazy on how to implement strict evaluation. I'm > thinking of creating a generic algorithm that looks something like the > following. > > We have the concept of a data construct that can be built step by step. At > each step are choices. We are investigating all the choices and finding > series of choices that lead to a completed data construct or "solution." We > want to generate a list of all solutions. > > (My Haskell syntax is rusty so there may be errors in the following.) > > > class Construct a where > enumerateChoices :: a -> [b] > applyChoice :: a -> b -> a > isSolution :: a -> Bool > > backtrack :: Construct a => a -> [a] > backtrack c > | isSolution c = [c] > | otherwise = > concat . map (backtrack . applyChoice c) . enumerateChoices $ c > > So my question is whether this is going to use a lot of memory to run, > maybe by holding all partially solved data? Where would strict evaluation > go? > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From courtney at crlog.info Sun Mar 16 12:03:03 2014 From: courtney at crlog.info (Courtney Robinson) Date: Sun, 16 Mar 2014 12:03:03 +0000 Subject: [Haskell-beginners] Thames Valley functional meetup Message-ID: Hello all, For anyone in the Thames valley area (UK) interested in a more local functional meetup. We've just started one. It's available at http://www.meetup.com/Thames-Valley-Functional-Programming-Meetup/ We'll be covering Haskell and a host of other functional languages in the talks. Already got the first one lined up for Haskell, Scala and OCaml (to be confirmed). See http://www.meetup.com/Thames-Valley-Functional-Programming-Meetup/events/171168272/ Hope to see you there. -- Courtney Robinson courtney at crlog.info http://crlog.info 07535691628 (No private #s) -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Sun Mar 16 13:34:00 2014 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Sun, 16 Mar 2014 20:34:00 +0700 Subject: [Haskell-beginners] Thames Valley functional meetup In-Reply-To: References: Message-ID: On Sun, Mar 16, 2014 at 7:03 PM, Courtney Robinson wrote: > For anyone in the Thames valley area (UK) interested in a more local > functional meetup. > We've just started one. > Afaict, the haskell-beginners list is way smaller than haskell-cafe so it's worth re-sending to the latter. Also reddit /r/haskell is a good place too, just ignore the downvotes. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From poczta at emanuelkoczwara.pl Sun Mar 16 17:32:36 2014 From: poczta at emanuelkoczwara.pl (Emanuel Koczwara) Date: Sun, 16 Mar 2014 18:32:36 +0100 Subject: [Haskell-beginners] RPC library / generic application level protocol Message-ID: <1394991156.20062.47.camel@emanuel-laptop> Hi, I have an application in c++/qt (https://gitorious.org/micropos). Direct connection with PostgreSQL is a big security hole, so I'm trying to redesign my architecture. I want to add an application server between PostgreSQL and client/admin and I want to write that application in Haskell. The core concept of my new architecture is a custom protocol. With that, it would be possible with little effort to create web and mobile clients, possibly using different technologies. Totally custom protocol would be interesting, but writing a parser for c ++ _and_ python _and_ java (and haskell of course) will be too much for me at the moment. XML-RPC looks too heavy, so I ended up with JSON-RPC ('id' attribute is ommited): * authentication example: | > { method: "auth-login", params: { name: , passwd: } } | < { result: } | > { method: "auth-logout", params: null } | < { result: } * uploading/downloading binary data/files example: | > { method: "fs-upload", params: } | { result: } | > { method: "fs-download", params: } | < { result: } * low level generic database methods: | > { method: "db-create", params: { type: , object: } } | < { result: } | > { method: "db-update", params: { type: , object: } } | < { result: } | > { method: "db-delete", params: { type: , id: } } | < { result: } | > { method: "db-list", params: | { type: , | filter-by: [ ], | order-by: [ ] } } | < { result: [ ] } | > { method: "db-show", params: | { type: , | ids: [ ], | fields: [ ] } } | < { result: [ ] } | > { method: "db-list-show", params: | { type: , | filter-by: [ ], | order-by: [ ], | fields: [ ] } } | < { result: [ ] } * low level generic relations: | > { method: "db-insert", params: | { group-type: , | group-id: , | member-type: , | members: [ ] } } | < { result: } | > { method: "db-remove", params: | { group-type: , | group-id: , | member-type: , | members: [ ] } } | < { result: } Example usage (this should add a record in 'client' table): | > { method: "db-create", params: | { type: client, | object:{ name:"John Doe", address: "...", ... } } } | < { result: } This 'parsing engine' should be generated from some kind of 'routes description' like in django, rails or yesod. For example something like this: | auth-login (user-name :: String) (user-password :: String) | auth-logout | auth-lock | auth-unlock (user-name :: String) (user-code :: String) | fs-upload (binary-data :: BinaryData) | fs-download (binary-data-id :: BinaryDataId) | db-create (type :: String) (object :: a) | db-update (type :: String) (object :: a) | db-delete (type :: String) (id :: String) The user should supply all data definitions and conversion functions to guarantee type corectness in case of a match, for example: class FromJson a where fromJson :: String -> Maybe a data Client = Client { name :: String, address :: String, ... } instance FromJason Client where fromJson = ... This looks very generic. Am I reinventing the wheel? Which package should I use for this task? msgpack-rpc looks interesting. Other packages have very low download rate. Or maybe there is some kind of generic appliaction server (but I'm looking for tcp/ip level, no http)? Any hints are very welcome. Thanks, Emanuel From dennis.raddle at gmail.com Sun Mar 16 21:25:06 2014 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Sun, 16 Mar 2014 14:25:06 -0700 Subject: [Haskell-beginners] backtracking search and memory usage In-Reply-To: References: Message-ID: thanks, that's some great perspective. I love how computer scientists think generally like that. I have several specific problems in mind and in those problems, the backtracking state is always built by adding pieces and never taking them away,and a full solution always requires the same number of pieces. So basically there isn't an opportunity for loops to form. Your advice to narrow the scope and build something that runs before worrying about performance issues is good advice, advice I would probably give myself or a younger programmer at times, but a lesson I still need to learn in other ways. Mike On Sat, Mar 15, 2014 at 9:08 AM, Kim-Ee Yeoh wrote: > Let's look at the requirements for this problem, uncovering some of the > unspoken ones: > > 1. very general problem > 2. fast, or at least not too slow > 3. memory-efficient > 4. correct > > Leaving aside performance issues 2 and 3, is it possible that 1 and 4 > alone are enough to deliver plenty of heartburn? > > I can think of at least one class of problems: the enumeration and > application of choices lead to cyclical states. Hence resulting in a list > of solutions pockmarked with bottoms. > > I mean your backtrack function is a correct and succinct description of > the very notion of backtracking. The devil is in the details of state > design, including the enumeration and application issues I've described. > > By narrowing the scope of the problem so that you first obtain a library > that correctly solves it, you could then focus on performance issues. > > > -- Kim-Ee > > > On Sat, Mar 15, 2014 at 9:06 AM, Dennis Raddle wrote: > >> I want to implement backtracking search, but I wonder if I'm going to >> immediately run into memory usage problems if I don't use strict evaluation >> somewhere. I'm very hazy on how to implement strict evaluation. I'm >> thinking of creating a generic algorithm that looks something like the >> following. >> >> We have the concept of a data construct that can be built step by step. >> At each step are choices. We are investigating all the choices and finding >> series of choices that lead to a completed data construct or "solution." We >> want to generate a list of all solutions. >> >> (My Haskell syntax is rusty so there may be errors in the following.) >> >> >> class Construct a where >> enumerateChoices :: a -> [b] >> applyChoice :: a -> b -> a >> isSolution :: a -> Bool >> >> backtrack :: Construct a => a -> [a] >> backtrack c >> | isSolution c = [c] >> | otherwise = >> concat . map (backtrack . applyChoice c) . enumerateChoices $ c >> >> So my question is whether this is going to use a lot of memory to run, >> maybe by holding all partially solved data? Where would strict evaluation >> go? >> >> >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://www.haskell.org/mailman/listinfo/beginners >> >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From javran.c at gmail.com Mon Mar 17 07:44:11 2014 From: javran.c at gmail.com (Javran Cheng) Date: Mon, 17 Mar 2014 03:44:11 -0400 Subject: [Haskell-beginners] Capture the notion of invertible functions Message-ID: Hi, These days I find the notion of "inverse function" might be useful, the basic idea is to keep a pair of function f and g which are the inverse functions of each other and then manipulate on this pair of functions. The detail is both on my blog post: http://javran.github.io/posts/2014-03-17-capture-the-notion-of-invertible-functions.html and also code review: http://codereview.stackexchange.com/questions/44550/capture-the-notion-of-invertible-functions I think this is an interesting idea and want to share it with you. Advice and comments are welcomed and appreciated since I learn haskell through LYAH and some wiki pages and still not sure about what would be the most idiomatic way of doing it in haskell. Thanks, -- Javran (Fang) Cheng -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Mon Mar 17 13:28:35 2014 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Mon, 17 Mar 2014 20:28:35 +0700 Subject: [Haskell-beginners] Capture the notion of invertible functions In-Reply-To: References: Message-ID: Hi Javran, 1. Have you looked at iso lens? The lens library contextualizes isomorphisms among other interesting maps. Worth looking into. 2. Your code looks nicely idiomatic. You must have worked hard observing models of good haskell. 3. It's easy to declare at the type-level: a->b and b->a. It's just that the types don't say anything about whether they are isos or not. Whereas that's what we want. Typically when I have such a pair of functions, I lean on quickcheck to give me a rapid verify as I tweak away, e.g.: prop_encdecOk :: String -> Bool prop_encdecOk xs = xs == (decode . encode $ xs) -- Kim-Ee On Mon, Mar 17, 2014 at 2:44 PM, Javran Cheng wrote: > Hi, > > These days I find the notion of "inverse function" might be useful, > the basic idea is to keep a pair of function f and g which are the inverse > functions of each other > and then manipulate on this pair of functions. > > The detail is both on my blog post: > > > http://javran.github.io/posts/2014-03-17-capture-the-notion-of-invertible-functions.html > > and also code review: > > > http://codereview.stackexchange.com/questions/44550/capture-the-notion-of-invertible-functions > > I think this is an interesting idea and want to share it with you. > Advice and comments are welcomed and appreciated since I learn haskell > through LYAH and some wiki pages > and still not sure about what would be the most idiomatic way of doing it > in haskell. > > Thanks, > > -- > Javran (Fang) Cheng > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nrujac at gmail.com Mon Mar 17 13:38:19 2014 From: nrujac at gmail.com (Arjun Comar) Date: Mon, 17 Mar 2014 09:38:19 -0400 Subject: [Haskell-beginners] Capture the notion of invertible functions In-Reply-To: References: Message-ID: Adding to Kim-Ee's point, 1) When you're talking about invertible functions, the idea you're probably reaching for is an isomorphism -- that is, we want the function to have certain nice properties on top of just being a map from a -> b with an inverse map from b -> a. You also want the function to be a bijection, which is captured in the notion of an isomorphism. 2) Iso from Lens composes with the normal function composition operator (.) instead of rappend -- which is a little more convenient. Arjun On Mon, Mar 17, 2014 at 9:28 AM, Kim-Ee Yeoh wrote: > Hi Javran, > > 1. Have you looked at iso lens? The lens library contextualizes > isomorphisms among other interesting maps. Worth looking into. > > 2. Your code looks nicely idiomatic. You must have worked hard observing > models of good haskell. > > 3. It's easy to declare at the type-level: a->b and b->a. It's just that > the types don't say anything about whether they are isos or not. Whereas > that's what we want. > > Typically when I have such a pair of functions, I lean on quickcheck to > give me a rapid verify as I tweak away, e.g.: > > prop_encdecOk :: String -> Bool > prop_encdecOk xs = xs == (decode . encode $ xs) > > > -- Kim-Ee > > > On Mon, Mar 17, 2014 at 2:44 PM, Javran Cheng wrote: > >> Hi, >> >> These days I find the notion of "inverse function" might be useful, >> the basic idea is to keep a pair of function f and g which are the >> inverse functions of each other >> and then manipulate on this pair of functions. >> >> The detail is both on my blog post: >> >> >> http://javran.github.io/posts/2014-03-17-capture-the-notion-of-invertible-functions.html >> >> and also code review: >> >> >> http://codereview.stackexchange.com/questions/44550/capture-the-notion-of-invertible-functions >> >> I think this is an interesting idea and want to share it with you. >> Advice and comments are welcomed and appreciated since I learn haskell >> through LYAH and some wiki pages >> and still not sure about what would be the most idiomatic way of doing it >> in haskell. >> >> Thanks, >> >> -- >> Javran (Fang) Cheng >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://www.haskell.org/mailman/listinfo/beginners >> >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dennis.raddle at gmail.com Mon Mar 17 19:14:31 2014 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Mon, 17 Mar 2014 12:14:31 -0700 Subject: [Haskell-beginners] Ambiguous type variables Message-ID: I need help with an "ambiguous type variables" error. My problem domain is backtracking search to construct musical phrases by choosing notes that fulfill as many simultaneous criteria as possible. At the beginning, I always know that I need to choose N notes, and they will be chosen in a particular order, one at a time. I don't need to worry about cycles, therefore. There is a way of calculating a "goodness" score, given a series of the first M notes (where M ranges from 2 to N). I'm looking for the solution with the best score. Because my problem may be too large to do a complete search, I think it would be great to be able to do a combination of breadth and depth searching... sort of like a chess program that searches X moves ahead but not all the way to the end of the game. So I start with 1 note and do a complete search on all partial solutions with X notes looking for the best score (dealing with ties somehow, not sure yet how), then take the first note from the best solution, then do a complete search on all partial solutions with 2 to X+1 notes, and so forth until X=N. I have in mind many possible ways of representing phrases and "moves," so I wanted to implement my basic algorithm in a class. I need three data types: - "the data" : a representation of a solution with from 1 to N choices applied - "a choice" : a representation of a choice of note at a particular point in the phrase - "memo" : a way of tracking the best partial solution(s) found during this phase of the search Here's my code so far In the following the type variable "d" is "the data", "c" is "a choice" and "memo" is a memo. The error is Ambiguous type variables 'd0', 'c0' in the constraint: (Bt d0 c0 memo) arising from a use of 'newMemo' class Bt d c memo | d -> c, d -> memo where -- a solution state is checked against the best solutions stored in -- the memo, and possibly replaces or augments the list of best -- solutions. updateMemo :: memo -> d -> memo newMemo :: memo pickBest :: Int -> memo -> d isSolution :: d -> Bool isSolution x = stateSize x == solutionSize x -- number of choices applied so far stateSize :: d -> Int -- note that data of type 'd' includes an indication of what the -- final solution size is, something put there when d is initialized solutionSize :: d -> Int enumerateChoices :: d -> [c] -- choices available at this point in the -- construction of the state -- compute a goodness score scoreState :: d -> Double applyChoice :: d -> c -> d -- note that this is only partially implemented. Never mind that -- it's not complete or correct, I'm still trying to understand -- where my error arises. -- -- What is will eventually do: completely searches N levels deep -- before picking best score, then takes best partial solution, -- backs up N-1 levels and does another complete search, -- etc. finally displays solution with best score. limBacktrack :: Int -> d -> memo limBacktrack n d = limBacktrack' n newMemo d limBacktrack' :: Int -> memo -> d -> memo limBacktrack' nGoal memo d | stateSize d == nGoal = updateMemo memo d | otherwise = foldl g memo (enumerateChoices d) where -- g :: memo -> choice -> memo g memo choice = limBacktrack' nGoal memo (applyChoice d choice) The error is Ambiguous type variables 'd0', 'c0' in the constraint: (Bt d0 c0 memo) arising from a use of 'newMemo' -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Mon Mar 17 19:48:21 2014 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Tue, 18 Mar 2014 02:48:21 +0700 Subject: [Haskell-beginners] Capture the notion of invertible functions In-Reply-To: References: Message-ID: > When you're talking about invertible functions, the idea you're probably reaching for is an isomorphism -- that is, we want the function to have certain nice properties on top of just being a map from a -> b with an inverse map from b -> a. The usual meaning of 'f is invertible' is that it is both left- and right-invertible, thus making it bijective: see first bullet in [1]. Here you're alluding to f being merely left-invertible, something I don't see mentioned in OP. > You also want the function to be a bijection, which is captured in the notion of an isomorphism. I'm reminded of a reddit convo where the idea was tossed out that semigroups should always be promoted to monoids [2]. I argued no. I also cited a case where a supposedly nicer monoid causes more problems for a ghc hacker than the true semigroup [3]. Having structure is nice. And sometimes we just have to work with what's given to us. Category theory calls a /monomorphism/ something that's strictly weaker than left-invertible. An arrow that's (additionally) left-invertible corresponds to a /split mono/. Hence in order of _decreasing_ niceness: Iso, Split mono, Mono. As research uncovers more interesting phenomena, this sequence will continuing growing to the right. We can't always impose that niceness because that nukes whatever we're studying. So we gotta respect the situation. And given lemons, make lemonade. [1] http://en.wikipedia.org/wiki/Bijection,_injection_and_surjection#Bijection [2] http://www.reddit.com/r/haskell/comments/1ou06l/improving_applicative_donotation/ccvtqot?context=1 [3] http://www.reddit.com/r/haskell/comments/1ou06l/improving_applicative_donotation/ccy4n2d -------------- next part -------------- An HTML attachment was scrubbed... URL: From byorgey at seas.upenn.edu Mon Mar 17 20:02:21 2014 From: byorgey at seas.upenn.edu (Brent Yorgey) Date: Mon, 17 Mar 2014 16:02:21 -0400 Subject: [Haskell-beginners] Ambiguous type variables In-Reply-To: References: Message-ID: <20140317200220.GA11705@seas.upenn.edu> On Mon, Mar 17, 2014 at 12:14:31PM -0700, Dennis Raddle wrote: > > The error is > > Ambiguous type variables 'd0', 'c0' in the constraint: > (Bt d0 c0 memo) arising from a use of 'newMemo' > > class Bt d c memo | d -> c, d -> memo where > > newMemo :: memo This is because given a use of 'newMemo', the compiler will be able to infer the type 'memo' from the context in which it is used, but there is no way for it to infer the types d and c. Hence they are ambiguous. There could be overlapping instances like instance Bt Int Int Char ... instance Bt Bool String Char ... so knowing memo=Char does not tell us what d and c are. (Note the compiler still refuses to make a choice even if there is only one matching instance in scope, because new instances could always be added in another module.) I can think of several possible solutions: 1. Add some functional dependencies memo -> d, memo -> c. This would "solve" the error though it is probably not what you want. 2. Add some 'dummy' arguments to newMemo (and other functions with a similar problem), like newMemo :: Proxy d -> memo However, this is a bit annoying to call since it requires giving a Proxy argument with a type signature. 3. Make Bt a record rather than a type class. This might actually be your best bet. You have to manually pass around Bt records, but you get to fully specify the types involved. -Brent From ky3 at atamo.com Mon Mar 17 20:28:59 2014 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Tue, 18 Mar 2014 03:28:59 +0700 Subject: [Haskell-beginners] Ambiguous type variables In-Reply-To: References: Message-ID: On Tue, Mar 18, 2014 at 2:14 AM, Dennis Raddle wrote: > class Bt d c memo | d -> c, d -> memo where Could you also say something about the instances you intend to implement for this typeclass? If there's only 1, which the statement of the problem suggests as much, you can dispense of the typeclass entirely and just work with plain functions! Could be that you want something working first and generalize / polymorphize later. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From dennis.raddle at gmail.com Mon Mar 17 22:56:05 2014 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Mon, 17 Mar 2014 15:56:05 -0700 Subject: [Haskell-beginners] Ambiguous type variables In-Reply-To: References: Message-ID: On Mon, Mar 17, 2014 at 1:28 PM, Kim-Ee Yeoh wrote: > > On Tue, Mar 18, 2014 at 2:14 AM, Dennis Raddle wrote: > >> class Bt d c memo | d -> c, d -> memo where > > > Could you also say something about the instances you intend to implement > for this typeclass? > > If there's only 1, which the statement of the problem suggests as much, > you can dispense of the typeclass entirely and just work with plain > functions! > > Could be that you want something working first and generalize / > polymorphize later. > I don't know yet how I want to represent the solution being searched for; i.e. I don't know how I want to represent musical structures, and I need the freedom to try different ones without rewriting my code. I also wanted to implement a few toy problems to do testing on my algorithm. But, you are absolutely right that I am generalizing too quickly. I worked on a toy problem today and had several insights. I noticed that some problems have specifics that don't fit the same mold. -Dennis -------------- next part -------------- An HTML attachment was scrubbed... URL: From gilbertomelfe at gmail.com Tue Mar 18 09:46:42 2014 From: gilbertomelfe at gmail.com (Gilberto Melfe) Date: Tue, 18 Mar 2014 09:46:42 +0000 Subject: [Haskell-beginners] cabal install Message-ID: Good morning, Good people of the haskell community! I need to develop a web(site)/application. I want to try using Yesod. First thing i need to install it. (I already have the haskell-platform) So I run: cabal update It tells me that a new version of cabal-install is available; then I run: cabal install cabal-install After doing whatever it wants to do, successfully (at least that's what I think the logs say; I didn't notice any error) I update my path to: export PATH=/home/.../.cabal/bin:$PATH Everything is "OK" now! But I still don't have a cabal-install binary, and this update has been performed only for me (inside my user account)! Shouldn't I have a binary cabal-install to run? How can I update globally? (for all users of the system!) After this I'm going to try to install Yesod! And of course I would like to install for all users of the system (yes I'm the only one:-) but I'm just asking...) Can anyone help me out? Thank You very much! Gilberto -------------- next part -------------- An HTML attachment was scrubbed... URL: From andres.loeh at googlemail.com Tue Mar 18 10:54:21 2014 From: andres.loeh at googlemail.com (=?ISO-8859-1?Q?Andres_L=F6h?=) Date: Tue, 18 Mar 2014 11:54:21 +0100 Subject: [Haskell-beginners] cabal install In-Reply-To: References: Message-ID: Hi. > After doing whatever it wants to do, successfully (at least that's what I > think the logs say; I didn't notice any error) I update my path to: > export PATH=/home/.../.cabal/bin:$PATH > > Everything is "OK" now! But I still don't have a cabal-install binary, and > this update has been performed only for me (inside my user account)! > > Shouldn't I have a binary cabal-install to run? The binary is called "cabal", not "cabal-install". You should be able to check whether the new version is being used by saying "cabal --version". > How can I update globally? (for all users of the system!) By saying something like "sudo cabal install --global cabal-install". Cheers, Andres From miguel.negrao-lists at friendlyvirus.org Tue Mar 18 11:53:42 2014 From: miguel.negrao-lists at friendlyvirus.org (=?ISO-8859-1?Q?Miguel_Negr=E3o?=) Date: Tue, 18 Mar 2014 11:53:42 +0000 Subject: [Haskell-beginners] emacs + ghc-mod + cabal repl Message-ID: <532833C6.6070505@friendlyvirus.org> Hi Can anyone tell me how switch from using ghci to cabal repl in emacs with ghc-mod ? I would like to use emacs with cabal projects with sandboxes, where ghci will not load the right packages. best, -- Miguel Negr?o http://www.friendlyvirus.org/miguelnegrao -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 555 bytes Desc: OpenPGP digital signature URL: From fuuzetsu at fuuzetsu.co.uk Tue Mar 18 15:49:49 2014 From: fuuzetsu at fuuzetsu.co.uk (Mateusz Kowalczyk) Date: Tue, 18 Mar 2014 15:49:49 +0000 Subject: [Haskell-beginners] emacs + ghc-mod + cabal repl In-Reply-To: <532833C6.6070505@friendlyvirus.org> References: <532833C6.6070505@friendlyvirus.org> Message-ID: <53286B1D.9030506@fuuzetsu.co.uk> On 18/03/14 11:53, Miguel Negr?o wrote: > Hi > > Can anyone tell me how switch from using ghci to cabal repl in emacs > with ghc-mod ? I would like to use emacs with cabal projects with > sandboxes, where ghci will not load the right packages. > > best, > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > Personally I evaluate (setq haskell-program-name "cabal repl") . Make sure you are in the same directory as the cabal file when you first start up the REPL. If you get complaints about not being able to find prompt, check the *haskell* buffer that gets created in the background to see what's going wrong. -- Mateusz K. From byorgey at seas.upenn.edu Tue Mar 18 17:02:11 2014 From: byorgey at seas.upenn.edu (Brent Yorgey) Date: Tue, 18 Mar 2014 13:02:11 -0400 Subject: [Haskell-beginners] cabal install In-Reply-To: References: Message-ID: <20140318170211.GA7327@seas.upenn.edu> On Tue, Mar 18, 2014 at 11:54:21AM +0100, Andres L?h wrote: > Hi. > > > After doing whatever it wants to do, successfully (at least that's what I > > think the logs say; I didn't notice any error) I update my path to: > > export PATH=/home/.../.cabal/bin:$PATH > > > > Everything is "OK" now! But I still don't have a cabal-install binary, and > > this update has been performed only for me (inside my user account)! > > > > Shouldn't I have a binary cabal-install to run? > > The binary is called "cabal", not "cabal-install". You should be able > to check whether the new version is being used by saying "cabal > --version". > > > How can I update globally? (for all users of the system!) > > By saying something like "sudo cabal install --global > cabal-install". Incidentally, it's better to say cabal install --root-cmd=sudo --global cabal-install That way, cabal will only acquire root privileges for the installation. It does not need to run as root for the entire downloading, building, etc. process, and in fact doing so can be bad, since it pollutes your package cache with files owned by root, leading to potential permissions problems in the future. -Brent From andres.loeh at googlemail.com Tue Mar 18 18:27:30 2014 From: andres.loeh at googlemail.com (=?ISO-8859-1?Q?Andres_L=F6h?=) Date: Tue, 18 Mar 2014 19:27:30 +0100 Subject: [Haskell-beginners] cabal install In-Reply-To: <20140318170211.GA7327@seas.upenn.edu> References: <20140318170211.GA7327@seas.upenn.edu> Message-ID: Hi Brent. >> By saying something like "sudo cabal install --global >> cabal-install". > > Incidentally, it's better to say > > cabal install --root-cmd=sudo --global cabal-install Ah yes, absolutely true. Thanks for pointing this out. I never actually run "cabal install --global" manually, so I forgot that this is possible. Cheers, Andres From miguel.negrao-lists at friendlyvirus.org Tue Mar 18 18:47:10 2014 From: miguel.negrao-lists at friendlyvirus.org (=?ISO-8859-1?Q?Miguel_Negr=E3o?=) Date: Tue, 18 Mar 2014 18:47:10 +0000 Subject: [Haskell-beginners] emacs + ghc-mod + cabal repl In-Reply-To: <53286B1D.9030506@fuuzetsu.co.uk> References: <532833C6.6070505@friendlyvirus.org> <53286B1D.9030506@fuuzetsu.co.uk> Message-ID: <532894AE.5010206@friendlyvirus.org> Em 18-03-2014 15:49, Mateusz Kowalczyk escreveu: > (setq haskell-program-name "cabal repl") thanks, that works. best, Miguel -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 555 bytes Desc: OpenPGP digital signature URL: From ky3 at atamo.com Tue Mar 18 20:04:26 2014 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Wed, 19 Mar 2014 03:04:26 +0700 Subject: [Haskell-beginners] cabal install In-Reply-To: <20140318170211.GA7327@seas.upenn.edu> References: <20140318170211.GA7327@seas.upenn.edu> Message-ID: On Wed, Mar 19, 2014 at 12:02 AM, Brent Yorgey wrote: > cabal install --root-cmd=sudo --global cabal-install > > That way, cabal will only acquire root privileges for the > installation. It does not need to run as root for the entire > downloading, building, etc. process, and in fact doing so can be bad, > since it pollutes your package cache with files owned by root, leading > to potential permissions problems in the future. > Oh my. This is some long magical incantation. Is this documented somewhere? At least in the cabal faq? -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From byorgey at seas.upenn.edu Tue Mar 18 20:39:34 2014 From: byorgey at seas.upenn.edu (Brent Yorgey) Date: Tue, 18 Mar 2014 16:39:34 -0400 Subject: [Haskell-beginners] cabal install In-Reply-To: References: <20140318170211.GA7327@seas.upenn.edu> Message-ID: <20140318203933.GA24646@seas.upenn.edu> On Wed, Mar 19, 2014 at 03:04:26AM +0700, Kim-Ee Yeoh wrote: > On Wed, Mar 19, 2014 at 12:02 AM, Brent Yorgey wrote: > > > cabal install --root-cmd=sudo --global cabal-install > > > > That way, cabal will only acquire root privileges for the > > installation. It does not need to run as root for the entire > > downloading, building, etc. process, and in fact doing so can be bad, > > since it pollutes your package cache with files owned by root, leading > > to potential permissions problems in the future. > > > > Oh my. This is some long magical incantation. > > Is this documented somewhere? At least in the cabal faq? I don't know, I learned it from Duncan Coutts. For the record, I don't actually recommend that people do this. I can only think of a few situations where this is really what you want to do (e.g. if you are setting up a multi-user system that students in a class are going to use). More typically, you should leave the Haskell Platform in your global package DB and then install everything else in your local user DB. That makes it much easier to start over if things get messed up, without having to reinstall the Haskell Platform. For something like cabal-install which is just an executable, if you want to make it available globally it is easy enough to build it locally and then copy it somewhere to make it available. -Brent From allbery.b at gmail.com Tue Mar 18 21:06:12 2014 From: allbery.b at gmail.com (Brandon Allbery) Date: Tue, 18 Mar 2014 17:06:12 -0400 Subject: [Haskell-beginners] cabal install In-Reply-To: References: <20140318170211.GA7327@seas.upenn.edu> Message-ID: On Tue, Mar 18, 2014 at 4:04 PM, Kim-Ee Yeoh wrote: > > On Wed, Mar 19, 2014 at 12:02 AM, Brent Yorgey wrote: > >> cabal install --root-cmd=sudo --global cabal-install >> > Oh my. This is some long magical incantation. > Is this documented somewhere? At least in the cabal faq? > Probably not since it's strongly disrecommended to do global installs. -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From dennis.raddle at gmail.com Wed Mar 19 01:47:31 2014 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Tue, 18 Mar 2014 18:47:31 -0700 Subject: [Haskell-beginners] Ambiguous type variables In-Reply-To: References: Message-ID: I have another question, speaking of optimizing too soon. My data structures will be things like rows of musical notes, implementable easily as lists of lists. But I will often need to do things like replace one element in a list. Should I use Array's? As I see it, lists get me certain simplicity, and many operations using the natural syntax will be concise. But then I'll have to do searches or random access and replacement. What criteria does one use to make decisions like this? Do the easiest one first and optimize later? I'm not even sure which is easiest as I don't think there is a list element replacement function in the libraries. On Mon, Mar 17, 2014 at 3:56 PM, Dennis Raddle wrote: > > > > On Mon, Mar 17, 2014 at 1:28 PM, Kim-Ee Yeoh wrote: > >> >> On Tue, Mar 18, 2014 at 2:14 AM, Dennis Raddle wrote: >> >>> class Bt d c memo | d -> c, d -> memo where >> >> >> Could you also say something about the instances you intend to implement >> for this typeclass? >> >> If there's only 1, which the statement of the problem suggests as much, >> you can dispense of the typeclass entirely and just work with plain >> functions! >> >> Could be that you want something working first and generalize / >> polymorphize later. >> > > > I don't know yet how I want to represent the solution being searched for; > i.e. I don't know how I want to represent musical structures, and I need > the freedom to try different ones without rewriting my code. I also wanted > to implement a few toy problems to do testing on my algorithm. > > But, you are absolutely right that I am generalizing too quickly. I worked > on a toy problem today and had several insights. I noticed that some > problems have specifics that don't fit the same mold. > -Dennis > -------------- next part -------------- An HTML attachment was scrubbed... URL: From miguel.negrao-lists at friendlyvirus.org Wed Mar 19 10:53:14 2014 From: miguel.negrao-lists at friendlyvirus.org (=?UTF-8?B?TWlndWVsIE5lZ3LDo28=?=) Date: Wed, 19 Mar 2014 10:53:14 +0000 Subject: [Haskell-beginners] emacs + ghc-mod + cabal repl In-Reply-To: <532894AE.5010206@friendlyvirus.org> References: <532833C6.6070505@friendlyvirus.org> <53286B1D.9030506@fuuzetsu.co.uk> <532894AE.5010206@friendlyvirus.org> Message-ID: <5329771A.1040100@friendlyvirus.org> Em 18-03-2014 18:47, Miguel Negr?o escreveu: Following that, a couple more questions: Is it possible to have the haddock help for functions displayed inside emacs (no browser) ? How does one jump to the defition of a symbol ? thanks, Miguel -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 555 bytes Desc: OpenPGP digital signature URL: From miroslav.karpis at gmail.com Wed Mar 19 10:55:22 2014 From: miroslav.karpis at gmail.com (Miroslav Karpis) Date: Wed, 19 Mar 2014 11:55:22 +0100 Subject: [Haskell-beginners] scotty - autorefresh / reload Message-ID: Hi, please is there a way how I could autorefresh / reload the page in scotty? A small example, where I would like to see that the time refreshes every second: {-# LANGUAGE OverloadedStrings #-} import Web.Scotty import Control.Monad.Trans (liftIO) import qualified Data.Text.Lazy as L (Text, pack) import Data.Time.Clock main = scotty 3005 $ do get "/" $ do time <- liftIO getTime html time getTime :: IO L.Text getTime = do utcTime <- getCurrentTime let timeText = L.pack $ show utcTime return timeText Cheers, M. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben.kolera at gmail.com Wed Mar 19 11:11:56 2014 From: ben.kolera at gmail.com (Ben Kolera) Date: Wed, 19 Mar 2014 21:11:56 +1000 Subject: [Haskell-beginners] scotty - autorefresh / reload In-Reply-To: References: Message-ID: If you explicitly want to avoid JavaScript / XHR you could use a meta refresh attribute in your HTML page: http://en.m.wikipedia.org/wiki/Meta_refresh Cheers, Ben On 19 Mar 2014 20:55, "Miroslav Karpis" wrote: > Hi, please is there a way how I could autorefresh / reload the page in > scotty? > > > A small example, where I would like to see that the time refreshes every > second: > > {-# LANGUAGE OverloadedStrings #-} > > import Web.Scotty > import Control.Monad.Trans (liftIO) > import qualified Data.Text.Lazy as L (Text, pack) > > import Data.Time.Clock > > main = scotty 3005 $ do > get "/" $ do > time <- liftIO getTime > html time > > > getTime :: IO L.Text > getTime = do > utcTime <- getCurrentTime > let timeText = L.pack $ show utcTime > return timeText > > > Cheers, > M. > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuuzetsu at fuuzetsu.co.uk Wed Mar 19 12:22:52 2014 From: fuuzetsu at fuuzetsu.co.uk (Mateusz Kowalczyk) Date: Wed, 19 Mar 2014 12:22:52 +0000 Subject: [Haskell-beginners] emacs + ghc-mod + cabal repl In-Reply-To: <5329771A.1040100@friendlyvirus.org> References: <532833C6.6070505@friendlyvirus.org> <53286B1D.9030506@fuuzetsu.co.uk> <532894AE.5010206@friendlyvirus.org> <5329771A.1040100@friendlyvirus.org> Message-ID: <53298C1C.5010506@fuuzetsu.co.uk> On 19/03/14 10:53, Miguel Negr?o wrote: > Em 18-03-2014 18:47, Miguel Negr?o escreveu: > > Following that, a couple more questions: > > Is it possible to have the haddock help for functions displayed inside > emacs (no browser) ? Not that I know of. GHCi doesn't support it (yet, maybe it will in the future) and Haskell interface files don't store this information so various tools can't get at it. I'm not aware of any tools that read the Haddock interface files and give you the docs that way. If someone/myself decides to go through with putting the Haddock strings into .hi files, reading documentation in your editor might become possible but I wouldn't hold my breath as it is completely in the ?it'd be cool if we had this? stage. > How does one jump to the defition of a symbol ? I use hasktags to generate the TAGS table and then use find-tag (bound to M-.) to jump to things. It works fine but it does tend to screw up sometimes. Of course it will only work if your definition is in the generated table, it won't do things like jumping to definitions in the libraries you use etc. I imagine that you could have a massive TAGS table generated from all your sources but I doubt it'd scale very well and would be close to impossible to maintain. It'd be great if we had something like Agda, where all the source is available so we can jump to anything at all, but we don't. > > thanks, > Miguel > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -- Mateusz K. From fuuzetsu at fuuzetsu.co.uk Wed Mar 19 12:38:53 2014 From: fuuzetsu at fuuzetsu.co.uk (Mateusz Kowalczyk) Date: Wed, 19 Mar 2014 12:38:53 +0000 Subject: [Haskell-beginners] emacs + ghc-mod + cabal repl In-Reply-To: <53298C1C.5010506@fuuzetsu.co.uk> References: <532833C6.6070505@friendlyvirus.org> <53286B1D.9030506@fuuzetsu.co.uk> <532894AE.5010206@friendlyvirus.org> <5329771A.1040100@friendlyvirus.org> <53298C1C.5010506@fuuzetsu.co.uk> Message-ID: <53298FDD.2000200@fuuzetsu.co.uk> On 19/03/14 12:22, Mateusz Kowalczyk wrote: > On 19/03/14 10:53, Miguel Negr?o wrote: >> Em 18-03-2014 18:47, Miguel Negr?o escreveu: >> >> Following that, a couple more questions: >> >> Is it possible to have the haddock help for functions displayed inside >> emacs (no browser) ? > > Not that I know of. GHCi doesn't support it (yet, maybe it will in the > future) and Haskell interface files don't store this information so > various tools can't get at it. I'm not aware of any tools that read the > Haddock interface files and give you the docs that way. If > someone/myself decides to go through with putting the Haddock strings > into .hi files, reading documentation in your editor might become > possible but I wouldn't hold my breath as it is completely in the ?it'd > be cool if we had this? stage. As a quick follow-up, it might be that Haddock itself will provide an interface to its own interface files and then various tools (and GHCi) can use that instead. Again, just ideas atm. > >> How does one jump to the defition of a symbol ? > > I use hasktags to generate the TAGS table and then use find-tag (bound > to M-.) to jump to things. It works fine but it does tend to screw up > sometimes. Of course it will only work if your definition is in the > generated table, it won't do things like jumping to definitions in the > libraries you use etc. I imagine that you could have a massive TAGS > table generated from all your sources but I doubt it'd scale very well > and would be close to impossible to maintain. > > It'd be great if we had something like Agda, where all the source is > available so we can jump to anything at all, but we don't. > >> >> thanks, >> Miguel >> >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://www.haskell.org/mailman/listinfo/beginners >> > > -- Mateusz K. From dennis.raddle at gmail.com Wed Mar 19 17:09:48 2014 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Wed, 19 Mar 2014 10:09:48 -0700 Subject: [Haskell-beginners] do Haskell programs have fewer bugs? Message-ID: I was thinking about why it seems I can write Haskell code without bugs in a much easier way than imperative languages. Part of it is the strict type-checking, but I think there is something more. It's the potential for conciseness. I work hard when programming in Haskell to take advantage of language features that make my program concise. Somehow this leads me to think about it in a certain way. I know I'm on track as it gets smaller and smaller. And as it gets smaller, it leads me to think about my logic's cases and things like that. Certain patterns show up and I think about what those patterns mean for the structure of my problem. By the time I'm done with all that, I've analyzed my problem much more thoroughly than I would ever do in an imperative language. Dennis -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Wed Mar 19 17:51:06 2014 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Thu, 20 Mar 2014 00:51:06 +0700 Subject: [Haskell-beginners] Ambiguous type variables In-Reply-To: References: Message-ID: On Wed, Mar 19, 2014 at 8:47 AM, Dennis Raddle wrote: > Do the easiest one first and optimize later? Yes. Fwiw, iterating in the zone doesn't even feel like iterating. > I'm not even sure which is easiest as I don't think there is a list > element replacement function in the libraries. It's a one-liner. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Wed Mar 19 18:15:34 2014 From: toad3k at gmail.com (David McBride) Date: Wed, 19 Mar 2014 14:15:34 -0400 Subject: [Haskell-beginners] Ambiguous type variables In-Reply-To: References: Message-ID: You might try Data.Sequence. Its update/take/drop/index etc all have nice performance and you can use Foldable.toList to convert it to a list whenever you feel a pressing need to use list pattern matching without sacrificing much performance. On Tue, Mar 18, 2014 at 9:47 PM, Dennis Raddle wrote: > I have another question, speaking of optimizing too soon. My data > structures will be things like rows of musical notes, implementable easily > as lists of lists. But I will often need to do things like replace one > element in a list. Should I use Array's? As I see it, lists get me certain > simplicity, and many operations using the natural syntax will be concise. > But then I'll have to do searches or random access and replacement. > > What criteria does one use to make decisions like this? Do the easiest one > first and optimize later? I'm not even sure which is easiest as I don't > think there is a list element replacement function in the libraries. > > > On Mon, Mar 17, 2014 at 3:56 PM, Dennis Raddle wrote: > >> >> >> >> On Mon, Mar 17, 2014 at 1:28 PM, Kim-Ee Yeoh wrote: >> >>> >>> On Tue, Mar 18, 2014 at 2:14 AM, Dennis Raddle wrote: >>> >>>> class Bt d c memo | d -> c, d -> memo where >>> >>> >>> Could you also say something about the instances you intend to implement >>> for this typeclass? >>> >>> If there's only 1, which the statement of the problem suggests as much, >>> you can dispense of the typeclass entirely and just work with plain >>> functions! >>> >>> Could be that you want something working first and generalize / >>> polymorphize later. >>> >> >> >> I don't know yet how I want to represent the solution being searched for; >> i.e. I don't know how I want to represent musical structures, and I need >> the freedom to try different ones without rewriting my code. I also wanted >> to implement a few toy problems to do testing on my algorithm. >> >> But, you are absolutely right that I am generalizing too quickly. I >> worked on a toy problem today and had several insights. I noticed that some >> problems have specifics that don't fit the same mold. >> -Dennis >> > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nadirsampaoli at gmail.com Wed Mar 19 18:21:39 2014 From: nadirsampaoli at gmail.com (Nadir Sampaoli) Date: Wed, 19 Mar 2014 19:21:39 +0100 Subject: [Haskell-beginners] do Haskell programs have fewer bugs? In-Reply-To: References: Message-ID: Hello, Il 19/mar/2014 18:09 "Dennis Raddle" ha scritto: > > I was thinking about why it seems I can write Haskell code without bugs in a much easier way than imperative languages. Part of it is the strict type-checking, but I think there is something more. As a beginner I find that the type system is my best friend. I spend most of the time in the repl trying function compositions until GHCi likes them. At that point, like I often read from expert haskellers' conversations, "if it typechecks it's most likely correct". > > It's the potential for conciseness. I work hard when programming in Haskell to take advantage of language features that make my program concise. As the saying goes, less code means less potential for bugs :) > > Somehow this leads me to think about it in a certain way. I know I'm on track as it gets smaller and smaller. And as it gets smaller, it leads me to think about my logic's cases and things like that. Certain patterns show up and I think about what those patterns mean for the structure of my problem. > > By the time I'm done with all that, I've analyzed my problem much more thoroughly than I would ever do in an imperative language. > > Dennis > As someone who is still struggling to get past that learning phase where you only solve "simple" (usually one-liner) exercises, I'd like to ask you (and anyone reading this) how do you reason at a larger level? At the function level Haskell feels like piping shell commands (which I find nice): a chain of successive transformations. How do you work at a larger (module/project) level? Do you need to have mastered all the main monads (beyond list amd maybe) and monad transformers? Sorry for the long rant. And thanks for the interesting discussion. -- Nadir -------------- next part -------------- An HTML attachment was scrubbed... URL: From dedgrant at gmail.com Wed Mar 19 18:29:58 2014 From: dedgrant at gmail.com (Darren Grant) Date: Wed, 19 Mar 2014 11:29:58 -0700 Subject: [Haskell-beginners] do Haskell programs have fewer bugs? In-Reply-To: References: Message-ID: For better or worse depending on your POV I find that I spend a lot of time looking at the implementations of many libraries I employ in larger projects. There are certainly some surprises when a program doesn't execute in the time or memory that I expected, and having the library source available can be invaluable for determining why. Cheers, Darren On Mar 19, 2014 11:21 AM, "Nadir Sampaoli" wrote: > Hello, > > Il 19/mar/2014 18:09 "Dennis Raddle" ha scritto: > > > > I was thinking about why it seems I can write Haskell code without bugs > in a much easier way than imperative languages. Part of it is the strict > type-checking, but I think there is something more. > > As a beginner I find that the type system is my best friend. I spend most > of the time in the repl trying function compositions until GHCi likes them. > At that point, like I often read from expert haskellers' conversations, "if > it typechecks it's most likely correct". > > > > > It's the potential for conciseness. I work hard when programming in > Haskell to take advantage of language features that make my program concise. > > As the saying goes, less code means less potential for bugs :) > > > > > Somehow this leads me to think about it in a certain way. I know I'm on > track as it gets smaller and smaller. And as it gets smaller, it leads me > to think about my logic's cases and things like that. Certain patterns show > up and I think about what those patterns mean for the structure of my > problem. > > > > By the time I'm done with all that, I've analyzed my problem much more > thoroughly than I would ever do in an imperative language. > > > > Dennis > > > > As someone who is still struggling to get past that learning phase where > you only solve "simple" (usually one-liner) exercises, I'd like to ask you > (and anyone reading this) how do you reason at a larger level? > At the function level Haskell feels like piping shell commands (which I > find nice): a chain of successive transformations. > How do you work at a larger (module/project) level? Do you need to have > mastered all the main monads (beyond list amd maybe) and monad transformers? > > Sorry for the long rant. And thanks for the interesting discussion. > > -- > Nadir > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From orclev at gmail.com Wed Mar 19 18:47:12 2014 From: orclev at gmail.com (Kyle Murphy) Date: Wed, 19 Mar 2014 14:47:12 -0400 Subject: [Haskell-beginners] do Haskell programs have fewer bugs? In-Reply-To: References: Message-ID: >From my experience so far it's largely the same, but you start to try to take advantage of some of the more advanced types to handle of lot of the plumbing type tasks. Things like Applicative and Monad make it simpler to shuffle data and context between (or around) functions. In general picking the right abstraction over your data goes a long way towards making your code easier to work with and more succinct. Aside from that it's really much like the case with individual functions, it's about composing larger operations from smaller ones until eventually you reach the program level where you're composing a handful of very coarse functions that comprise the totality of the program. -R. Kyle Murphy -- Curiosity was framed, Ignorance killed the cat. On Wed, Mar 19, 2014 at 2:21 PM, Nadir Sampaoli wrote: > Hello, > > Il 19/mar/2014 18:09 "Dennis Raddle" ha scritto: > > > > > I was thinking about why it seems I can write Haskell code without bugs > in a much easier way than imperative languages. Part of it is the strict > type-checking, but I think there is something more. > > As a beginner I find that the type system is my best friend. I spend most > of the time in the repl trying function compositions until GHCi likes them. > At that point, like I often read from expert haskellers' conversations, "if > it typechecks it's most likely correct". > > > > > It's the potential for conciseness. I work hard when programming in > Haskell to take advantage of language features that make my program concise. > > As the saying goes, less code means less potential for bugs :) > > > > > Somehow this leads me to think about it in a certain way. I know I'm on > track as it gets smaller and smaller. And as it gets smaller, it leads me > to think about my logic's cases and things like that. Certain patterns show > up and I think about what those patterns mean for the structure of my > problem. > > > > By the time I'm done with all that, I've analyzed my problem much more > thoroughly than I would ever do in an imperative language. > > > > Dennis > > > > As someone who is still struggling to get past that learning phase where > you only solve "simple" (usually one-liner) exercises, I'd like to ask you > (and anyone reading this) how do you reason at a larger level? > At the function level Haskell feels like piping shell commands (which I > find nice): a chain of successive transformations. > How do you work at a larger (module/project) level? Do you need to have > mastered all the main monads (beyond list amd maybe) and monad transformers? > > Sorry for the long rant. And thanks for the interesting discussion. > > -- > Nadir > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ryan.trinkle at gmail.com Wed Mar 19 18:52:32 2014 From: ryan.trinkle at gmail.com (Ryan Trinkle) Date: Wed, 19 Mar 2014 14:52:32 -0400 Subject: [Haskell-beginners] do Haskell programs have fewer bugs? In-Reply-To: References: Message-ID: Hi Dennis, At skedge.me, our platform is Haskell on the backend and JavaScript on the frontend, and we've definitely found that we have far fewer bugs coming out of the backend than the frontend. I think Haskell's language features (including the type system and sum types, most prominently) are responsible for much of this difference. We've also been able to completely eliminate certain kinds of bugs, such as accidentally performing side effects during a database transaction (which might be rolled back), by using monads to enforce our application's layer architecture. It's certainly possible to write very buggy code in Haskell, but Haskell gives you a lot of tools that you can use to prevent yourself from writing bugs. In my experience, it is much more efficient than achieving the same level of quality using only testing. Ryan On Wed, Mar 19, 2014 at 1:09 PM, Dennis Raddle wrote: > I was thinking about why it seems I can write Haskell code without bugs in > a much easier way than imperative languages. Part of it is the strict > type-checking, but I think there is something more. It's the potential for > conciseness. I work hard when programming in Haskell to take advantage of > language features that make my program concise. Somehow this leads me to > think about it in a certain way. I know I'm on track as it gets smaller and > smaller. And as it gets smaller, it leads me to think about my logic's > cases and things like that. Certain patterns show up and I think about what > those patterns mean for the structure of my problem. > > By the time I'm done with all that, I've analyzed my problem much more > thoroughly than I would ever do in an imperative language. > > Dennis > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From orblivion at gmail.com Wed Mar 19 18:58:37 2014 From: orblivion at gmail.com (Dan Krol) Date: Wed, 19 Mar 2014 11:58:37 -0700 Subject: [Haskell-beginners] do Haskell programs have fewer bugs? In-Reply-To: References: Message-ID: Perhaps a bit tangential to the general question of "fewer bugs", but I'll tell you that Haskell really clicked for me when I made a very nuanced refactor of code that, while it took me a half day to sort out the type errors, worked perfectly the first time I ran it. And this was for audio generation stuff, something that's rather hard to debug in a usual way, so I'm grateful that I didn't have to. There's no way it would work so smoothly in, say, C++. Granted, I threw a whole lot of types at it, because I was working with transformations between and operations within different sorts of domains that I didn't want to get mixed up. So, you sometimes have to deliberately leverage the tools to get it to do the magic for you. On Wed, Mar 19, 2014 at 11:47 AM, Kyle Murphy wrote: > From my experience so far it's largely the same, but you start to try to > take advantage of some of the more advanced types to handle of lot of the > plumbing type tasks. Things like Applicative and Monad make it simpler to > shuffle data and context between (or around) functions. In general picking > the right abstraction over your data goes a long way towards making your > code easier to work with and more succinct. Aside from that it's really > much like the case with individual functions, it's about composing larger > operations from smaller ones until eventually you reach the program level > where you're composing a handful of very coarse functions that comprise the > totality of the program. > > -R. Kyle Murphy > -- > Curiosity was framed, Ignorance killed the cat. > > > On Wed, Mar 19, 2014 at 2:21 PM, Nadir Sampaoli wrote: > >> Hello, >> >> Il 19/mar/2014 18:09 "Dennis Raddle" ha >> scritto: >> >> > >> > I was thinking about why it seems I can write Haskell code without bugs >> in a much easier way than imperative languages. Part of it is the strict >> type-checking, but I think there is something more. >> >> As a beginner I find that the type system is my best friend. I spend most >> of the time in the repl trying function compositions until GHCi likes them. >> At that point, like I often read from expert haskellers' conversations, "if >> it typechecks it's most likely correct". >> >> > >> > It's the potential for conciseness. I work hard when programming in >> Haskell to take advantage of language features that make my program concise. >> >> As the saying goes, less code means less potential for bugs :) >> >> > >> > Somehow this leads me to think about it in a certain way. I know I'm on >> track as it gets smaller and smaller. And as it gets smaller, it leads me >> to think about my logic's cases and things like that. Certain patterns show >> up and I think about what those patterns mean for the structure of my >> problem. >> > >> > By the time I'm done with all that, I've analyzed my problem much more >> thoroughly than I would ever do in an imperative language. >> > >> > Dennis >> > >> >> As someone who is still struggling to get past that learning phase where >> you only solve "simple" (usually one-liner) exercises, I'd like to ask you >> (and anyone reading this) how do you reason at a larger level? >> At the function level Haskell feels like piping shell commands (which I >> find nice): a chain of successive transformations. >> How do you work at a larger (module/project) level? Do you need to have >> mastered all the main monads (beyond list amd maybe) and monad transformers? >> >> Sorry for the long rant. And thanks for the interesting discussion. >> >> -- >> Nadir >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://www.haskell.org/mailman/listinfo/beginners >> >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Wed Mar 19 22:51:09 2014 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Thu, 20 Mar 2014 05:51:09 +0700 Subject: [Haskell-beginners] do Haskell programs have fewer bugs? In-Reply-To: References: Message-ID: On Thu, Mar 20, 2014 at 1:21 AM, Nadir Sampaoli wrote: > As the saying goes, less code means less potential for bugs :) > But you should look out for code golf, which isn't helpful. > As someone who is still struggling to get past that learning phase where > you only solve "simple" (usually one-liner) exercises, I'd like to ask you > (and anyone reading this) how do you reason at a larger level? > There's a lot of low-lying fruit that's easily plucked leveraging functional programming. I list the easiest ones that I know of here: http://www.atamo.com/blog/low-lying-fruits-of-fp-1/ Of course, you still have to grapple and understand your specific problem domain, whether it's web apps or auto music generation. > How do you work at a larger (module/project) level? Do you need to have > mastered all the main monads (beyond list amd maybe) and monad transformers? > > Don't sweat them monads. The codebase for GHC doesn't even use monad transformers iirc. Sorry for the long rant. > Not at all. Haskell mailing lists used to have long, discursive discussions, but somehow this one turned into some kind of rapid-fire Q&A. Most of the interesting knowledge can't be unpacked in that format. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From javran.c at gmail.com Thu Mar 20 06:18:12 2014 From: javran.c at gmail.com (Javran Cheng) Date: Thu, 20 Mar 2014 02:18:12 -0400 Subject: [Haskell-beginners] Capture the notion of invertible Message-ID: I've tried that lens lib out, and it is exactly what I want. few examples in GHCi: ?> let pretty x = mapM_ print x ?> pretty mat [1,0,0,0,2] [0,3,0,4,0] [0,0,5,0,0] [0,6,0,7,0] [8,0,0,0,9] ?> let shiftL = filter (/= 0) >>> (++ repeat 0) >>> take 5 ?> over (iso transpose transpose) (map shiftL) mat [[1,3,5,4,2],[8,6,0,7,9],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] ?> pretty $ over (iso transpose transpose) (map shiftL) mat [1,3,5,4,2] [8,6,0,7,9] [0,0,0,0,0] [0,0,0,0,0] [0,0,0,0,0] ?> pretty $ over ((iso transpose transpose).(iso (map reverse) (map reverse) )) (map shiftL) mat [0,0,0,0,0] [0,0,0,0,0] [0,0,0,0,0] [1,3,0,4,2] [8,6,5,7,9] Off topic: In addition, as David Young commented in my codereview question: "rempty and rappend form a Category instance. " This comment makes perfect sense to me, because "monoid-like" reminds me of Data.Monoid, which does not totally capture what I know about monoid: monad is "just a monoid in the category of endofunctors" but Monad is not in any sense fit into a Monoid. Here I find that when I talk about "monoid-like", I actually refer to Category, and Monad is an instance of Category, which backs up my guess. In a word, can I say that when talking about reducing data (Sum, Product, etc.), I'm referring to Monoid, and when I talking about monoid-like composition, I'm referring to Category? Javran > Date: Tue, 18 Mar 2014 02:48:21 +0700 > From: Kim-Ee Yeoh > To: The Haskell-Beginners Mailing List - Discussion of primarily > beginner-level topics related to Haskell > Subject: Re: [Haskell-beginners] Capture the notion of invertible > functions > Message-ID: > > Content-Type: text/plain; charset="iso-8859-1" > > > When you're talking about invertible functions, the idea you're probably > reaching for is an isomorphism -- that is, we want the function to have > certain nice properties on top of just being a map from a -> b with an > inverse map from b -> a. > > The usual meaning of 'f is invertible' is that it is both left- and > right-invertible, thus making it bijective: see first bullet in [1]. > > Here you're alluding to f being merely left-invertible, something I don't > see mentioned in OP. > > > You also want the function to be a bijection, which is captured in the > notion of an isomorphism. > > I'm reminded of a reddit convo where the idea was tossed out that > semigroups should always be promoted to monoids [2]. > > I argued no. I also cited a case where a supposedly nicer monoid causes > more problems for a ghc hacker than the true semigroup [3]. > > Having structure is nice. And sometimes we just have to work with what's > given to us. > > Category theory calls a /monomorphism/ something that's strictly weaker > than left-invertible. An arrow that's (additionally) left-invertible > corresponds to a /split mono/. > > Hence in order of _decreasing_ niceness: Iso, Split mono, Mono. As research > uncovers more interesting phenomena, this sequence will continuing growing > to the right. > > We can't always impose that niceness because that nukes whatever we're > studying. So we gotta respect the situation. And given lemons, make > lemonade. > > > [1] > http://en.wikipedia.org/wiki/Bijection,_injection_and_surjection#Bijection > > [2] > http://www.reddit.com/r/haskell/comments/1ou06l/improving_applicative_donotation/ccvtqot?context=1 > > [3] > http://www.reddit.com/r/haskell/comments/1ou06l/improving_applicative_donotation/ccy4n2d -- Javran (Fang) Cheng From nadirsampaoli at gmail.com Thu Mar 20 07:47:35 2014 From: nadirsampaoli at gmail.com (Nadir Sampaoli) Date: Thu, 20 Mar 2014 08:47:35 +0100 Subject: [Haskell-beginners] do Haskell programs have fewer bugs? In-Reply-To: References: Message-ID: Il 19/mar/2014 23:51 "Kim-Ee Yeoh" ha scritto: > > There's a lot of low-lying fruit that's easily plucked leveraging functional programming. Thanks for the insight. The "don't"s are most helpful. I have to constantly take myself from code golfing and overcomplicating things for the sake of cleverness (especially in a language that enables you so much). >> >> How do you work at a larger (module/project) level? Do you need to have mastered all the main monads (beyond list amd maybe) and monad transformers? > > Don't sweat them monads. The codebase for GHC doesn't even use monad transformers iirc. My point was that when you're arranging new data types you'd probably benefit from understanding/recognizing behavioral patterns (e.g a Reader, a State-carrying data structure, etc.). Nonetheless I think I understand your point in which keeping things flat simple does come a long way to solving problems. > > Not at all. Haskell mailing lists used to have long, discursive discussions, but somehow this one turned into some kind of rapid-fire Q&A. Most of the interesting knowledge can't be unpacked in that format. Eh, that would imply a certain level of knowledge on both side. The fact that I'm stubborn and keep writing mails on a phone while train-commuting doesn't help either. > > -- Kim-Ee > Thanks again, Regards Nadir -------------- next part -------------- An HTML attachment was scrubbed... URL: From objitsu at gmail.com Thu Mar 20 13:36:34 2014 From: objitsu at gmail.com (emacstheviking) Date: Thu, 20 Mar 2014 13:36:34 +0000 Subject: [Haskell-beginners] do Haskell programs have fewer bugs? In-Reply-To: References: Message-ID: On the nail! That's exactly how I feel about using Haskell and it is the same feeling I had when I learned Lisp... for some reason you feel much more connected with the nature of the problem and therefore more aware / focused / cognisant of "what you are doing". I found that part of the reason, at leat for me, was the need to write "efficient" code, and that means taking time to read the libraries to see what is already available and thus you come across more than one potential way to solve your problem and thus have to think about it more. I think that Lisp and Haskell (and other languages that promote higher order programming) allow for powerful abstractions that result in functions like "map, filter, reject, fold" etc and thus remove theneed for manually writing loops in the code. That was part of the appeal for me, not coding loops! :) Sean. On 19 March 2014 17:09, Dennis Raddle wrote: > I was thinking about why it seems I can write Haskell code without bugs in > a much easier way than imperative languages. Part of it is the strict > type-checking, but I think there is something more. It's the potential for > conciseness. I work hard when programming in Haskell to take advantage of > language features that make my program concise. Somehow this leads me to > think about it in a certain way. I know I'm on track as it gets smaller and > smaller. And as it gets smaller, it leads me to think about my logic's > cases and things like that. Certain patterns show up and I think about what > those patterns mean for the structure of my problem. > > By the time I'm done with all that, I've analyzed my problem much more > thoroughly than I would ever do in an imperative language. > > Dennis > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From byorgey at seas.upenn.edu Thu Mar 20 13:47:30 2014 From: byorgey at seas.upenn.edu (Brent Yorgey) Date: Thu, 20 Mar 2014 09:47:30 -0400 Subject: [Haskell-beginners] Capture the notion of invertible In-Reply-To: References: Message-ID: <20140320134730.GA4285@seas.upenn.edu> On Thu, Mar 20, 2014 at 02:18:12AM -0400, Javran Cheng wrote: > Off topic: This is not off topic for the beginners list at all. =) > This comment makes perfect sense to me, because "monoid-like" reminds > me of Data.Monoid, > which does not totally capture what I know about monoid: monad is > "just a monoid in the category of endofunctors" The "monoid" being referred to here is a very generalized sense of the word, and is quite different from (though distantly related to) Haskell's Monoid type class. > but Monad is not in any sense fit into a Monoid. > Here I find that when I talk about "monoid-like", I actually refer to Category, > and Monad is an instance of Category, which backs up my guess. "Monad is an instance of Category" --- this doesn't really make sense as stated. It's certainly not true that every instance of Monad is also an instance of Category; the kinds don't even match. It is true that you can build a Category out of a Monad, though there are actually several ways to do so. The most well-known in the Haskell world is Kleisli, but there are other ways. > In a word, can I say that when talking about reducing data (Sum, > Product, etc.), I'm referring to Monoid, > and when I talking about monoid-like composition, I'm referring to > Category? "monoid-like composition" can refer to Monoid too. The essential difference is *types*: in particular you can think of a Category as a "typed Monoid": with a Monoid, *any* two things can be composed. With a Category, you can only compose things whose types match. So conversely you can also think of a Monoid as a "Category with only one type". As an (easy) exercise: newtype Endomorphism cat a = E (cat a a) instance Category cat => Monoid (Endomorphism cat a) where ... -Brent > > Javran > > > Date: Tue, 18 Mar 2014 02:48:21 +0700 > > From: Kim-Ee Yeoh > > To: The Haskell-Beginners Mailing List - Discussion of primarily > > beginner-level topics related to Haskell > > Subject: Re: [Haskell-beginners] Capture the notion of invertible > > functions > > Message-ID: > > > > Content-Type: text/plain; charset="iso-8859-1" > > > > > When you're talking about invertible functions, the idea you're probably > > reaching for is an isomorphism -- that is, we want the function to have > > certain nice properties on top of just being a map from a -> b with an > > inverse map from b -> a. > > > > The usual meaning of 'f is invertible' is that it is both left- and > > right-invertible, thus making it bijective: see first bullet in [1]. > > > > Here you're alluding to f being merely left-invertible, something I don't > > see mentioned in OP. > > > > > You also want the function to be a bijection, which is captured in the > > notion of an isomorphism. > > > > I'm reminded of a reddit convo where the idea was tossed out that > > semigroups should always be promoted to monoids [2]. > > > > I argued no. I also cited a case where a supposedly nicer monoid causes > > more problems for a ghc hacker than the true semigroup [3]. > > > > Having structure is nice. And sometimes we just have to work with what's > > given to us. > > > > Category theory calls a /monomorphism/ something that's strictly weaker > > than left-invertible. An arrow that's (additionally) left-invertible > > corresponds to a /split mono/. > > > > Hence in order of _decreasing_ niceness: Iso, Split mono, Mono. As research > > uncovers more interesting phenomena, this sequence will continuing growing > > to the right. > > > > We can't always impose that niceness because that nukes whatever we're > > studying. So we gotta respect the situation. And given lemons, make > > lemonade. > > > > > > [1] > > http://en.wikipedia.org/wiki/Bijection,_injection_and_surjection#Bijection > > > > [2] > > http://www.reddit.com/r/haskell/comments/1ou06l/improving_applicative_donotation/ccvtqot?context=1 > > > > [3] > > http://www.reddit.com/r/haskell/comments/1ou06l/improving_applicative_donotation/ccy4n2d > > > > > > -- > Javran (Fang) Cheng > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > From leilmyxwz at gmail.com Thu Mar 20 18:17:37 2014 From: leilmyxwz at gmail.com (bruce li) Date: Thu, 20 Mar 2014 14:17:37 -0400 Subject: [Haskell-beginners] What to do next? Message-ID: Hi, there, I'm relatively new to Haskell...well... I mean I haven't done anything I believe truely in Haskell. I have gone through materials like Learn You a Haskell for Real Good, Real World Haskell, most chapters in Haskell Wikibook, Write Yourself Scheme in 48 Hours, Algorithms: A Functional Approach and other materials in Haskell Wiki. *But... what I feel is that I'm not confident while writing Haskell code.*Having gone through all those materials with "magic", I always feel I'm writing stupid code and there must be more elegant way... And... what's worse, I feel guilty while using IO monad but I simply cannot avoid it, like when I try to write code generator for a toy compiler, I need to keep state of the registers, which I need IORef... Then I feel its not pure anymore but I don't know how to get around it. I'm wondering if anyone else shares this kind of feeling and what should I do next? Could anyone suggest any project to get hands on experience with Haskell? Another question is that the deeper digging into functional algorithms design (reading the book Pearls of Functional Algorithm Design), the more ignorant I feel. So how do I make up the basics like fold law, list induction etc. Any suggested reading materials? Well.. I think that's a lot question. Thanks for your patience and your kind help. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob at redivi.com Thu Mar 20 18:29:20 2014 From: bob at redivi.com (Bob Ippolito) Date: Thu, 20 Mar 2014 11:29:20 -0700 Subject: [Haskell-beginners] What to do next? In-Reply-To: References: Message-ID: I got a lot out of reading Parallel and Concurrent Programming in Haskell by Simon Marlow. Purely Functional Data Structures by Chris Okasaki is also quite useful. Haskell wasn't my first pure-ish FP language (I spent a lot of time in Erlang) so for me it was really about wrapping my head around Haskell's non-strict evaluation. You could also try going through the exercises at http://exercism.io/ - none of the exercises are too challenging but the code review component of the site will keep you honest and will likely help you get closer to writing better Haskell. On Thu, Mar 20, 2014 at 11:17 AM, bruce li wrote: > Hi, there, > I'm relatively new to Haskell...well... I mean I haven't done anything I > believe truely in Haskell. I have gone through materials like Learn You a > Haskell for Real Good, Real World Haskell, most chapters in Haskell > Wikibook, Write Yourself Scheme in 48 Hours, Algorithms: A Functional > Approach and other materials in Haskell Wiki. > > *But... what I feel is that I'm not confident while writing Haskell code.*Having gone through all those materials with "magic", I always feel I'm > writing stupid code and there must be more elegant way... And... what's > worse, I feel guilty while using IO monad but I simply cannot avoid it, > like when I try to write code generator for a toy compiler, I need to keep > state of the registers, which I need IORef... Then I feel its not pure > anymore but I don't know how to get around it. > > I'm wondering if anyone else shares this kind of feeling and what should I > do next? Could anyone suggest any project to get hands on experience with > Haskell? > > Another question is that the deeper digging into functional algorithms > design (reading the book Pearls of Functional Algorithm Design), the more > ignorant I feel. So how do I make up the basics like fold law, list > induction etc. Any suggested reading materials? > > Well.. I think that's a lot question. Thanks for your patience and your > kind help. > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuuzetsu at fuuzetsu.co.uk Thu Mar 20 19:08:35 2014 From: fuuzetsu at fuuzetsu.co.uk (Mateusz Kowalczyk) Date: Thu, 20 Mar 2014 19:08:35 +0000 Subject: [Haskell-beginners] What to do next? In-Reply-To: References: Message-ID: <532B3CB3.2060508@fuuzetsu.co.uk> On 20/03/14 18:17, bruce li wrote: > Hi, there, > I'm relatively new to Haskell...well... I mean I haven't done anything I > believe truely in Haskell. I have gone through materials like Learn You a > Haskell for Real Good, Real World Haskell, most chapters in Haskell > Wikibook, Write Yourself Scheme in 48 Hours, Algorithms: A Functional > Approach and other materials in Haskell Wiki. > > *But... what I feel is that I'm not confident while writing Haskell > code.*Having gone through all those materials with "magic", I always > feel I'm > writing stupid code and there must be more elegant way... And... what's > worse, I feel guilty while using IO monad but I simply cannot avoid it, > like when I try to write code generator for a toy compiler, I need to keep > state of the registers, which I need IORef... Then I feel its not pure > anymore but I don't know how to get around it. > > I'm wondering if anyone else shares this kind of feeling and what should I > do next? Could anyone suggest any project to get hands on experience with > Haskell? > > Another question is that the deeper digging into functional algorithms > design (reading the book Pearls of Functional Algorithm Design), the more > ignorant I feel. So how do I make up the basics like fold law, list > induction etc. Any suggested reading materials? > > Well.. I think that's a lot question. Thanks for your patience and your > kind help. > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > I recommend that you try and help out with existing libraries. Writing patches for libs is very easy in Haskell as it's quite hard to break everything by not setting that one obscure global variable there somewhere ;) Toy problems only get you so far, and this way others will benefit too. -- Mateusz K. From gilbertomelfe at gmail.com Thu Mar 20 19:46:35 2014 From: gilbertomelfe at gmail.com (Gilberto Melfe) Date: Thu, 20 Mar 2014 19:46:35 +0000 Subject: [Haskell-beginners] Installing Yesod! Message-ID: Hello People! I've been trying to get Yesod going! Updated cabal (as instructed). Installed the yesod-platform package. Next step, would be to install the yesod-bin package (for the yesod executable, server and stuff...)! But when I try: ./cabal install --dry-run yesod-bin I get these messages: Resolving dependencies... cabal: Could not resolve dependencies: trying: yesod-bin-1.2.7.3 (user goal) next goal: ghc (dependency of yesod-bin-1.2.7.3) Dependency tree exhaustively searched. I'm gonna get into trouble again, right? Can anyone tell me what to do next? Thank you very much! Gilberto -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosarioenzoluca.borda at gmail.com Thu Mar 20 19:50:04 2014 From: rosarioenzoluca.borda at gmail.com (Rosario Borda) Date: Thu, 20 Mar 2014 20:50:04 +0100 Subject: [Haskell-beginners] Haskell code as DSL Message-ID: Hello Haskellers, what about insert haskell code as DSL in haskell program? as an example, in ghci: > eval [haskell| tail [0,1,2,3]|] [1,2,3] as intermediate step to get an interactive word-based italian translation of haskell: > eval [italian| coda [0,1,2,3]|] [1,2,3] I'm an italian primary school teacher and I would like to introduce my schoolchildren to FP using haskell... Thank you very much, see You son. Rosario -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuuzetsu at fuuzetsu.co.uk Thu Mar 20 20:17:05 2014 From: fuuzetsu at fuuzetsu.co.uk (Mateusz Kowalczyk) Date: Thu, 20 Mar 2014 20:17:05 +0000 Subject: [Haskell-beginners] Haskell code as DSL In-Reply-To: References: Message-ID: <532B4CC1.1050009@fuuzetsu.co.uk> On 20/03/14 19:50, Rosario Borda wrote: > Hello Haskellers, > what about insert haskell code as DSL in haskell program? as an example, in > ghci: > >> eval [haskell| tail [0,1,2,3]|] > [1,2,3] > > as intermediate step to get an interactive word-based italian translation > of haskell: > >> eval [italian| coda [0,1,2,3]|] > [1,2,3] > > I'm an italian primary school teacher and I would like to introduce > my schoolchildren to FP using haskell... > > Thank you very much, see You son. > Rosario > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > What's wrong with making something like Prelude.Italian which re-exports the common functions under their Italian equivalents? It'd just contain things like coda = tail ? Isn't this much easier than messing with Template Haskell and effectively achieving the same thing? Maybe there's something I'm missing here. -- Mateusz K. From michael at snoyman.com Thu Mar 20 20:20:33 2014 From: michael at snoyman.com (Michael Snoyman) Date: Thu, 20 Mar 2014 22:20:33 +0200 Subject: [Haskell-beginners] Installing Yesod! In-Reply-To: References: Message-ID: Are you using the Fedora system installation of GHC by any chance? If so, the problem is that Fedora doesn't include GHC-as-a-library by default. See [1] for more details and how to resolve it. If you're *not* on Fedora, please provide more information on your OS and how you install GHC/Haskell Platform. [1] https://groups.google.com/d/msg/yesodweb/AM8VeHpu8IU/xtzjltFwcEgJ On Thu, Mar 20, 2014 at 9:46 PM, Gilberto Melfe wrote: > Hello People! > > I've been trying to get Yesod going! > > Updated cabal (as instructed). > Installed the yesod-platform package. > > Next step, would be to install the yesod-bin package (for the yesod > executable, server and stuff...)! But when I try: > > ./cabal install --dry-run yesod-bin > > I get these messages: > > Resolving dependencies... > cabal: Could not resolve dependencies: > trying: yesod-bin-1.2.7.3 (user goal) > next goal: ghc (dependency of yesod-bin-1.2.7.3) > Dependency tree exhaustively searched. > > I'm gonna get into trouble again, right? > > Can anyone tell me what to do next? > > Thank you very much! > > Gilberto > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From javran.c at gmail.com Thu Mar 20 20:25:07 2014 From: javran.c at gmail.com (Javran Cheng) Date: Thu, 20 Mar 2014 16:25:07 -0400 Subject: [Haskell-beginners] Capture the notion of invertible In-Reply-To: References: Message-ID: I thought every Monad is a Category because I see "instance Monad m => Category (Kleisli m)" in Control.Category, So what are the other ways? I tried to do the exercise: import Prelude hiding ((.), id) import Control.Category import Control.Arrow import Data.Monoid newtype Endomorphism cat a = E { runE :: cat a a } instance Category cat => Monoid (Endomorphism cat a) where mempty = E id (E g) `mappend` (E f) = E (g . f) testMonoid :: [Endomorphism (Kleisli []) Int] testMonoid = map (E . Kleisli) [ \x -> [x, x+1] , \x -> [x-1, x] , \x -> [x+10] ] main :: IO () main = print $ runKleisli (runE (mconcat testMonoid)) 10 -- [10] -- > [10,11] -- > [9,10, 10,11] -- > [19,20,20,21] Is this what you meant? Javran > Date: Thu, 20 Mar 2014 09:47:30 -0400 > From: Brent Yorgey > To: beginners at haskell.org > Subject: Re: [Haskell-beginners] Capture the notion of invertible > Message-ID: <20140320134730.GA4285 at seas.upenn.edu> > Content-Type: text/plain; charset=us-ascii > > On Thu, Mar 20, 2014 at 02:18:12AM -0400, Javran Cheng wrote: >> Off topic: > > This is not off topic for the beginners list at all. =) > >> This comment makes perfect sense to me, because "monoid-like" reminds >> me of Data.Monoid, >> which does not totally capture what I know about monoid: monad is >> "just a monoid in the category of endofunctors" > > The "monoid" being referred to here is a very generalized sense of the > word, and is quite different from (though distantly related to) > Haskell's Monoid type class. > >> but Monad is not in any sense fit into a Monoid. >> Here I find that when I talk about "monoid-like", I actually refer to Category, >> and Monad is an instance of Category, which backs up my guess. > > "Monad is an instance of Category" --- this doesn't really make > sense as stated. It's certainly not true that every instance of Monad > is also an instance of Category; the kinds don't even match. It is > true that you can build a Category out of a Monad, though there are > actually several ways to do so. The most well-known in the Haskell > world is Kleisli, but there are other ways. > >> In a word, can I say that when talking about reducing data (Sum, >> Product, etc.), I'm referring to Monoid, >> and when I talking about monoid-like composition, I'm referring to >> Category? > > "monoid-like composition" can refer to Monoid too. The essential > difference is *types*: in particular you can think of a Category as a > "typed Monoid": with a Monoid, *any* two things can be composed. With > a Category, you can only compose things whose types match. So > conversely you can also think of a Monoid as a "Category with only one > type". As an (easy) exercise: > > newtype Endomorphism cat a = E (cat a a) > > instance Category cat => Monoid (Endomorphism cat a) where > ... > > -Brent > >> >> Javran >> >> > Date: Tue, 18 Mar 2014 02:48:21 +0700 >> > From: Kim-Ee Yeoh >> > To: The Haskell-Beginners Mailing List - Discussion of primarily >> > beginner-level topics related to Haskell >> > Subject: Re: [Haskell-beginners] Capture the notion of invertible >> > functions >> > Message-ID: >> > >> > Content-Type: text/plain; charset="iso-8859-1" >> > >> > > When you're talking about invertible functions, the idea you're probably >> > reaching for is an isomorphism -- that is, we want the function to have >> > certain nice properties on top of just being a map from a -> b with an >> > inverse map from b -> a. >> > >> > The usual meaning of 'f is invertible' is that it is both left- and >> > right-invertible, thus making it bijective: see first bullet in [1]. >> > >> > Here you're alluding to f being merely left-invertible, something I don't >> > see mentioned in OP. >> > >> > > You also want the function to be a bijection, which is captured in the >> > notion of an isomorphism. >> > >> > I'm reminded of a reddit convo where the idea was tossed out that >> > semigroups should always be promoted to monoids [2]. >> > >> > I argued no. I also cited a case where a supposedly nicer monoid causes >> > more problems for a ghc hacker than the true semigroup [3]. >> > >> > Having structure is nice. And sometimes we just have to work with what's >> > given to us. >> > >> > Category theory calls a /monomorphism/ something that's strictly weaker >> > than left-invertible. An arrow that's (additionally) left-invertible >> > corresponds to a /split mono/. >> > >> > Hence in order of _decreasing_ niceness: Iso, Split mono, Mono. As research >> > uncovers more interesting phenomena, this sequence will continuing growing >> > to the right. >> > >> > We can't always impose that niceness because that nukes whatever we're >> > studying. So we gotta respect the situation. And given lemons, make >> > lemonade. >> > >> > >> > [1] >> > http://en.wikipedia.org/wiki/Bijection,_injection_and_surjection#Bijection >> > >> > [2] >> > http://www.reddit.com/r/haskell/comments/1ou06l/improving_applicative_donotation/ccvtqot?context=1 >> > >> > [3] >> > http://www.reddit.com/r/haskell/comments/1ou06l/improving_applicative_donotation/ccy4n2d >> >> >> >> >> >> -- >> Javran (Fang) Cheng >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://www.haskell.org/mailman/listinfo/beginners >> From byorgey at seas.upenn.edu Thu Mar 20 21:04:43 2014 From: byorgey at seas.upenn.edu (Brent Yorgey) Date: Thu, 20 Mar 2014 17:04:43 -0400 Subject: [Haskell-beginners] Capture the notion of invertible In-Reply-To: References: Message-ID: <20140320210443.GA22697@seas.upenn.edu> Hi Javran, On Thu, Mar 20, 2014 at 04:25:07PM -0400, Javran Cheng wrote: > I thought every Monad is a Category because I see > "instance Monad m => Category (Kleisli m)" in Control.Category, This does not say "every Monad is a Category". It says "Kleisli m is a Category whenever m is a Monad". So you could say "every Monad *gives rise to* (not *is*) a Category". > So what are the other ways? There is another construction called the Eilenberg-Moore category of a monad. I have never seen anyone encode it in Haskell; it would actually be difficult since the objects of the category would not be Haskell types but monad algebras (though I'm sure it is possible). The Category class can only encode categories whose objects are Haskell types. > I tried to do the exercise: > > newtype Endomorphism cat a = E { runE :: cat a a } > > instance Category cat => Monoid (Endomorphism cat a) where > mempty = E id > (E g) `mappend` (E f) = E (g . f) > > Is this what you meant? Yes, exactly right. -Brent > > Date: Thu, 20 Mar 2014 09:47:30 -0400 > > From: Brent Yorgey > > To: beginners at haskell.org > > Subject: Re: [Haskell-beginners] Capture the notion of invertible > > Message-ID: <20140320134730.GA4285 at seas.upenn.edu> > > Content-Type: text/plain; charset=us-ascii > > > > On Thu, Mar 20, 2014 at 02:18:12AM -0400, Javran Cheng wrote: > >> Off topic: > > > > This is not off topic for the beginners list at all. =) > > > >> This comment makes perfect sense to me, because "monoid-like" reminds > >> me of Data.Monoid, > >> which does not totally capture what I know about monoid: monad is > >> "just a monoid in the category of endofunctors" > > > > The "monoid" being referred to here is a very generalized sense of the > > word, and is quite different from (though distantly related to) > > Haskell's Monoid type class. > > > >> but Monad is not in any sense fit into a Monoid. > >> Here I find that when I talk about "monoid-like", I actually refer to Category, > >> and Monad is an instance of Category, which backs up my guess. > > > > "Monad is an instance of Category" --- this doesn't really make > > sense as stated. It's certainly not true that every instance of Monad > > is also an instance of Category; the kinds don't even match. It is > > true that you can build a Category out of a Monad, though there are > > actually several ways to do so. The most well-known in the Haskell > > world is Kleisli, but there are other ways. > > > >> In a word, can I say that when talking about reducing data (Sum, > >> Product, etc.), I'm referring to Monoid, > >> and when I talking about monoid-like composition, I'm referring to > >> Category? > > > > "monoid-like composition" can refer to Monoid too. The essential > > difference is *types*: in particular you can think of a Category as a > > "typed Monoid": with a Monoid, *any* two things can be composed. With > > a Category, you can only compose things whose types match. So > > conversely you can also think of a Monoid as a "Category with only one > > type". As an (easy) exercise: > > > > newtype Endomorphism cat a = E (cat a a) > > > > instance Category cat => Monoid (Endomorphism cat a) where > > ... > > > > -Brent > > > >> > >> Javran > >> > >> > Date: Tue, 18 Mar 2014 02:48:21 +0700 > >> > From: Kim-Ee Yeoh > >> > To: The Haskell-Beginners Mailing List - Discussion of primarily > >> > beginner-level topics related to Haskell > >> > Subject: Re: [Haskell-beginners] Capture the notion of invertible > >> > functions > >> > Message-ID: > >> > > >> > Content-Type: text/plain; charset="iso-8859-1" > >> > > >> > > When you're talking about invertible functions, the idea you're probably > >> > reaching for is an isomorphism -- that is, we want the function to have > >> > certain nice properties on top of just being a map from a -> b with an > >> > inverse map from b -> a. > >> > > >> > The usual meaning of 'f is invertible' is that it is both left- and > >> > right-invertible, thus making it bijective: see first bullet in [1]. > >> > > >> > Here you're alluding to f being merely left-invertible, something I don't > >> > see mentioned in OP. > >> > > >> > > You also want the function to be a bijection, which is captured in the > >> > notion of an isomorphism. > >> > > >> > I'm reminded of a reddit convo where the idea was tossed out that > >> > semigroups should always be promoted to monoids [2]. > >> > > >> > I argued no. I also cited a case where a supposedly nicer monoid causes > >> > more problems for a ghc hacker than the true semigroup [3]. > >> > > >> > Having structure is nice. And sometimes we just have to work with what's > >> > given to us. > >> > > >> > Category theory calls a /monomorphism/ something that's strictly weaker > >> > than left-invertible. An arrow that's (additionally) left-invertible > >> > corresponds to a /split mono/. > >> > > >> > Hence in order of _decreasing_ niceness: Iso, Split mono, Mono. As research > >> > uncovers more interesting phenomena, this sequence will continuing growing > >> > to the right. > >> > > >> > We can't always impose that niceness because that nukes whatever we're > >> > studying. So we gotta respect the situation. And given lemons, make > >> > lemonade. > >> > > >> > > >> > [1] > >> > http://en.wikipedia.org/wiki/Bijection,_injection_and_surjection#Bijection > >> > > >> > [2] > >> > http://www.reddit.com/r/haskell/comments/1ou06l/improving_applicative_donotation/ccvtqot?context=1 > >> > > >> > [3] > >> > http://www.reddit.com/r/haskell/comments/1ou06l/improving_applicative_donotation/ccy4n2d > >> > >> > >> > >> > >> > >> -- > >> Javran (Fang) Cheng > >> _______________________________________________ > >> Beginners mailing list > >> Beginners at haskell.org > >> http://www.haskell.org/mailman/listinfo/beginners > >> > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners From gilbertomelfe at gmail.com Thu Mar 20 22:07:58 2014 From: gilbertomelfe at gmail.com (Gilberto Melfe) Date: Thu, 20 Mar 2014 22:07:58 +0000 Subject: [Haskell-beginners] Installing Yesod! In-Reply-To: References: Message-ID: Thanks for the reply! I'm using openSUSE 13.1, and of all the packages "available" when I choose to install the Haskell Platform, only the ones unmarked in the image I attach to this reply, are not installed. I didn't install them because they were not selected by default; also I thought the ghc package might conflict with other stuff in the Haskell Platform (maybe it was standalone version of ghc). So I guess I should install: ghc, ghc-ghc and ghc-ghc-devel? Simple Yes/No (Maybe:-)... On Thu, Mar 20, 2014 at 8:20 PM, Michael Snoyman wrote: > Are you using the Fedora system installation of GHC by any chance? If so, > the problem is that Fedora doesn't include GHC-as-a-library by default. See > [1] for more details and how to resolve it. > > If you're *not* on Fedora, please provide more information on your OS and > how you install GHC/Haskell Platform. > > [1] https://groups.google.com/d/msg/yesodweb/AM8VeHpu8IU/xtzjltFwcEgJ > > ____________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: packages.png Type: image/png Size: 31745 bytes Desc: not available URL: From tonymorris at gmail.com Thu Mar 20 22:15:05 2014 From: tonymorris at gmail.com (Tony Morris) Date: Fri, 21 Mar 2014 08:15:05 +1000 Subject: [Haskell-beginners] What to do next? In-Reply-To: References: Message-ID: <532B6869.1020100@gmail.com> I teach FP for a living for an organisation called NICTA. This is the material I use primarily https://github.com/NICTA/course If you can do the easy stuff, fine. For example, https://github.com/NICTA/course/blob/master/src/Course/List.hs https://github.com/NICTA/course/blob/master/src/Course/ListZipper.hs https://github.com/NICTA/course/blob/master/src/Course/StateT.hs If you want it a bit harder: https://github.com/NICTA/course/blob/master/src/Course/Parser.hs https://github.com/NICTA/course/blob/master/src/Course/JsonParser.hs https://github.com/NICTA/course/blob/master/src/Course/Cheque.hs But if you can do any of these, then I would say you are not a beginner anymore: https://github.com/NICTA/course/blob/master/projects/TicTacToe/TicTacToe.markdown https://github.com/NICTA/course/blob/master/projects/NetworkServer/NetworkServer.markdown On 21/03/14 04:17, bruce li wrote: > Hi, there, > I'm relatively new to Haskell...well... I mean I haven't done anything > I believe truely in Haskell. I have gone through materials like Learn > You a Haskell for Real Good, Real World Haskell, most chapters in > Haskell Wikibook, Write Yourself Scheme in 48 Hours, Algorithms: A > Functional Approach and other materials in Haskell Wiki. > > *But... what I feel is that I'm not confident while writing Haskell > code.* Having gone through all those materials with "magic", I always > feel I'm writing stupid code and there must be more elegant way... > And... what's worse, I feel guilty while using IO monad but I simply > cannot avoid it, like when I try to write code generator for a toy > compiler, I need to keep state of the registers, which I need IORef... > Then I feel its not pure anymore but I don't know how to get around it. > > I'm wondering if anyone else shares this kind of feeling and what > should I do next? Could anyone suggest any project to get hands on > experience with Haskell? > > Another question is that the deeper digging into functional algorithms > design (reading the book Pearls of Functional Algorithm Design), the > more ignorant I feel. So how do I make up the basics like fold law, > list induction etc. Any suggested reading materials? > > Well.. I think that's a lot question. Thanks for your patience and > your kind help. > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners -- Tony Morris http://tmorris.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From dennis.raddle at gmail.com Fri Mar 21 01:22:09 2014 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Thu, 20 Mar 2014 18:22:09 -0700 Subject: [Haskell-beginners] suggestions for code improvement Message-ID: This is a fairly complex problem and I don't expect anyone to follow it all, but I thought I would just post it and see if anyone can immediately identify unidiomatic Haskell. The problem is this: I'm writing a program that does backtrack search to determine musical counterpoint. I begin by laying out a series of "cells" which are notes of *as yet undetermined* pitch but do have determined begin time and duration (and also the instrument playing them is known). The algorithm will find pitches for each cell in order to maximize a fitness function. Cells can overlap in time. The search algorithm is allowed to make some cells silent if that improves the final result. So each cell has a status which is one of the following "undecided," "determined a specific pitch," and "determined to be silent". data CellStatus = CellUndecided -- Undecided whether this cell will be a -- pitch or silent | CellSilent -- It has been decided that this cell will be -- silent | CellPitch Pitch -- This cell will be a specific pitch deriving(Show) The following code deals with only one aspect of the fitness function. When there are patterns in the music called "octave relations," it makes the solution a bad one that should be avoided. An octave relation is when some note, say a C, appears as a following C in a different octave and fclose in time. It's okay to repeat the same C, just not in a different octave. In some atonal styles of music octave relations need to be specially handled or avoided altogether. So this is an algorithm that determines if any octave relations are present. There are two kinds of octave relations between a cell A and a cell B (containing an octave relation). One happens when A and B overlap in time. Clearly that represent a very close juxtaposition of A and B and it's illegal. The next kind of octave relation happens when B follows A some time later, but there are very few intervening notes of other pitches. The idea is that if *a lot of notes* intervene, it distracts the ear and the octave relation is not audible. But if only a few intervene between A and B, the octave relation will really stand out. Another bit of trickery. Consider the cells that intervene between A and B; that is, notes that start *after the end of A* and *before the beginning of B*. Some of those might have a status of CellUndecided. Those notes count as helping to distract the ear because we know we are eventually going to fill them in. But cells with a status of CellSilent don't count. And of course, notes of CellPitch status count as distracting the ear (unless they represent an octave relation). Here's the code. If anyone actually wants to run this, I can email you some test data. import Data.Maybe import Data.Map(Map) import qualified Data.Map as M import qualified Data.List as L type Time = Int type Pitch = Int data Cell = Cell { endTime :: Time , cellStatus :: CellStatus } deriving(Show) data CellStatus = CellUndecided -- Undecided whether this cell will be a -- pitch or silent | CellSilent -- It has been decided that this cell will be -- silent | CellPitch Pitch -- This cell will be a specific pitch deriving(Show) -- maps a given Time to a list of Cells that *begin* at that time type TimeMap = Map Time [Cell] -- checkOctaveRelations -- -- Int :: all octave relations must be have at least this many -- intervening notes -- TimeMap :: map of Time to list of Cells at that time -- -- Result True if satisfies the condition that all octave relations -- have at least proper number of intervening notes (or there are no -- octave relations), False otherwise. -- checkOctaveRelations :: Int -> TimeMap -> Bool checkOctaveRelations condition timeMap = all checkOneTime . M.keys $ timeMap where -- check all notes at one begin time to verify they satisfy the condition. -- note that we assume this function is called with 'beginTime' in ascending -- time order, so we only check notes at or following 'beginTime' checkOneTime :: Int -> Bool checkOneTime beginTime | checkBunch cellsAtBeginTime = False -- this is the case that among -- all cells at 'beginTime', there -- are octave relations within -- them | otherwise = all checkOneCell cellsAtBeginTime where cellsAtBeginTime = fromJust . M.lookup beginTime $ timeMap checkOneCell :: Cell -> Bool checkOneCell cell -- the line below checks the case that any overlapping cells have -- octave relations | any (any (isOctRel cell)) overlappingCells = False -- otherwise count the number of intervening cells until the -- next octave relation | otherwise = case countFollowingNonOctRel cell followingCells of Nothing -> True -- no octave relatios were found following -- 'cell' - so condition is met Just count -> count >= condition where (Cell endTime _) = cell followingCells = M.elems . snd . M.split (endTime-1) $ timeMap overlappingCells = M.elems . M.filterWithKey (\k _ -> k > beginTime && k < endTime) $ timeMap -- countFollowingNonOctRel -- -- count the number N of cells that do not have an octave relation -- with input 'c' before encountering an octave relation. Result is Just N. -- if no octave relations are found at all, result is Nothing. countFollowingNonOctRel :: Cell -> [[Cell]] -> Maybe Int countFollowingNonOctRel c cellGroups = case L.findIndex (\cells -> any (isOctRel c) cells) cellGroups of Nothing -> Nothing Just idx -> Just . sum . map countCells . take idx $ cellGroups where countCells :: [Cell] -> Int countCells cells = sum . map countFn $ cells countFn (Cell _ CellSilent) = 0 -- silent cells are not distracting; don't count as any countFn _ = 1 -- other cells count as distracting -- checkBunch -- -- Check a group of cells that all occur at the same time for any octave -- relations in any pair of cells checkBunch :: [Cell] -> Bool checkBunch [] = False checkBunch (c:cs) = (any (\c' -> isOctRel c c') cs) || checkBunch cs isOctRel :: Cell -> Cell -> Bool isOctRel cell1 cell2 | isCellPitch cell1 && isCellPitch cell2 = isOctRel' cell1 cell2 | otherwise = False where isOctRel' (Cell _ (CellPitch p1)) (Cell _ (CellPitch p2)) = p1 /= p2 && p1 `mod` 12 == p2 `mod` 12 isCellPitch (Cell _ (CellPitch _)) = True isCellPitch _ = False isCellSilent (Cell _ CellSilent) = True isCellSilent _ = False -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael at snoyman.com Fri Mar 21 04:49:16 2014 From: michael at snoyman.com (Michael Snoyman) Date: Fri, 21 Mar 2014 06:49:16 +0200 Subject: [Haskell-beginners] Installing Yesod! In-Reply-To: References: Message-ID: I'll go with "maybe" :) On Fri, Mar 21, 2014 at 12:07 AM, Gilberto Melfe wrote: > Thanks for the reply! > > I'm using openSUSE 13.1, and of all the packages "available" when I choose > to install the Haskell Platform, only the ones unmarked in the image I > attach to this reply, are not installed. > > I didn't install them because they were not selected by default; also I > thought the ghc package might conflict with other stuff in the Haskell > Platform (maybe it was standalone version of ghc). > > So I guess I should install: ghc, ghc-ghc and ghc-ghc-devel? > > Simple Yes/No (Maybe:-)... > > > On Thu, Mar 20, 2014 at 8:20 PM, Michael Snoyman wrote: > >> Are you using the Fedora system installation of GHC by any chance? If so, >> the problem is that Fedora doesn't include GHC-as-a-library by default. See >> [1] for more details and how to resolve it. >> >> If you're *not* on Fedora, please provide more information on your OS and >> how you install GHC/Haskell Platform. >> >> [1] https://groups.google.com/d/msg/yesodweb/AM8VeHpu8IU/xtzjltFwcEgJ >> >> ____________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://www.haskell.org/mailman/listinfo/beginners >> >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From javran.c at gmail.com Fri Mar 21 11:31:57 2014 From: javran.c at gmail.com (Javran Cheng) Date: Fri, 21 Mar 2014 07:31:57 -0400 Subject: [Haskell-beginners] Implement semantic editor combinators Message-ID: Hi, I read Conal Elliott's "Semantic editor combinators" and write myself a tutorial to answer how it works and give some observations about it, here I want to share it with you: http://javran.github.io/posts/2014-03-21-implement-semantic-editor-combinators.html Hope you enjoy it and please feel free to give me comments and indicate my misconceptions. Thanks, Javran From ky3 at atamo.com Fri Mar 21 16:59:48 2014 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Fri, 21 Mar 2014 23:59:48 +0700 Subject: [Haskell-beginners] Haskell code as DSL In-Reply-To: <532B4CC1.1050009@fuuzetsu.co.uk> References: <532B4CC1.1050009@fuuzetsu.co.uk> Message-ID: On Fri, Mar 21, 2014 at 3:17 AM, Mateusz Kowalczyk wrote: > What's wrong with making something like Prelude.Italian which re-exports > the common functions under their Italian equivalents? > Yes, a Prelude with Italian names is a great idea! -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Fri Mar 21 22:19:08 2014 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Sat, 22 Mar 2014 05:19:08 +0700 Subject: [Haskell-beginners] Implement semantic editor combinators In-Reply-To: References: Message-ID: On Fri, Mar 21, 2014 at 6:31 PM, Javran Cheng wrote: > Hope you enjoy it and please feel free to give me comments and > indicate my misconceptions. > A couple of things come to mind: you could * Ping @conal whether via email or twitter -- he's very friendly and likes helping students. And since you worked hard at one of his blog entries, you just might make his day! (I could also introduce you to him -- just ask.) * Have you looked at the lens library? What would the code look like using lenses instead of SECs? A comparison would reveal tons of insights -- please blog and share for everyone! -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Sat Mar 22 15:32:37 2014 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Sat, 22 Mar 2014 22:32:37 +0700 Subject: [Haskell-beginners] suggestions for code improvement In-Reply-To: References: Message-ID: On Fri, Mar 21, 2014 at 8:22 AM, Dennis Raddle wrote: > This is a fairly complex problem I'm sure you're right about this. > and I don't expect anyone to follow it all, but I thought I would just > post it and see if anyone can immediately identify unidiomatic Haskell. Have you run it through hlint? What does it say? Let us know if there's anything in hlint's output that's befuddling -- treat it more as a syntax h(l)inter than a syntax (h)linter. p.s. A note about exposition: consider providing some input & output examples to illustrate what these functions are up to. The preceding paragraphs indicate twisty exceptions and special cases that are hard-going for the casual reader. Which means fewer eyeballs on your email. p.p.s. Are there any interesting properties of these functions that you could leverage quickcheck on? -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosarioenzoluca.borda at gmail.com Sat Mar 22 17:15:37 2014 From: rosarioenzoluca.borda at gmail.com (Rosario Borda) Date: Sat, 22 Mar 2014 18:15:37 +0100 Subject: [Haskell-beginners] Haskell code as DSL In-Reply-To: References: <532B4CC1.1050009@fuuzetsu.co.uk> Message-ID: Thank You, but are the keywords of haskell translatable using the "function" approach suggested (case, of - data - ...)? Rosario 2014-03-21 17:59 GMT+01:00 Kim-Ee Yeoh : > > On Fri, Mar 21, 2014 at 3:17 AM, Mateusz Kowalczyk < > fuuzetsu at fuuzetsu.co.uk> wrote: > >> What's wrong with making something like Prelude.Italian which re-exports >> the common functions under their Italian equivalents? >> > > Yes, a Prelude with Italian names is a great idea! > > -- Kim-Ee > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuuzetsu at fuuzetsu.co.uk Sat Mar 22 17:37:23 2014 From: fuuzetsu at fuuzetsu.co.uk (Mateusz Kowalczyk) Date: Sat, 22 Mar 2014 17:37:23 +0000 Subject: [Haskell-beginners] Haskell code as DSL In-Reply-To: References: <532B4CC1.1050009@fuuzetsu.co.uk> Message-ID: <532DCA53.3000901@fuuzetsu.co.uk> On 22/03/14 17:15, Rosario Borda wrote: > Thank You, > but are the keywords of haskell translatable using the "function" approach > suggested (case, of - data - ...)? > > Rosario > > > 2014-03-21 17:59 GMT+01:00 Kim-Ee Yeoh : > >> >> On Fri, Mar 21, 2014 at 3:17 AM, Mateusz Kowalczyk < >> fuuzetsu at fuuzetsu.co.uk> wrote: >> >>> What's wrong with making something like Prelude.Italian which re-exports >>> the common functions under their Italian equivalents? >>> >> >> Yes, a Prelude with Italian names is a great idea! >> >> -- Kim-Ee >> No, they aren't but considering how few keywords Haskell has, this shouldn't be a problem and your students would learn some Haskell rather than some Template Haskelled wrapper around it which they can't relate to when they go and look stuff up. case of data newtype module if then else class type do where let newtype instance import qualified as hiding pattern proc That's just about it and you won't be using all of these at once either. If you really want to go with ?translate everything? approach, what are you going to do about error messages? Even if you alias the used built-in types, GHC will still often strip the alias. I understand translating some function names because there are many functions and it's easier to remember what it does if it's a word you know, but I think going beyond that is going to be harmful in a long run. If you want to introduce your students to FP using Haskell then please use Haskell! Using TH to hide Haskell seems counter-intuitive. I'm sceptic whether the word ?instance? or ?module? will mean anything more to young students whether it's in English or Italian. -- Mateusz K. From ky3 at atamo.com Sat Mar 22 17:56:36 2014 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Sun, 23 Mar 2014 00:56:36 +0700 Subject: [Haskell-beginners] Haskell code as DSL In-Reply-To: <532DCA53.3000901@fuuzetsu.co.uk> References: <532B4CC1.1050009@fuuzetsu.co.uk> <532DCA53.3000901@fuuzetsu.co.uk> Message-ID: On Sun, Mar 23, 2014 at 12:37 AM, Mateusz Kowalczyk wrote: > If you really want to go with 'translate everything' approach, what are > you going to do about error messages? > That's a good point. A fully language-native Haskell environment seems to be sought-after here, and that's a major undertaking. TH, if anything, could blow up with even more error messages when fed slightly off syntax. These are primary schoolchildren, yes? To summarize, the choices available include: 1. nativize Prelude, let children grapple with English keywords 2. use sed scripts or some editor feature to translate italian .ihs to .hs before feeding into interpreter/compiler. 3. nativize Prelude & keywords by recompiling with necessary tweaks to the keyword table. But errors still in English tho. 4. full i18n If GHC isn't a must, option 3 just might be a 10-minute job for hugs. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosarioenzoluca.borda at gmail.com Sat Mar 22 20:38:43 2014 From: rosarioenzoluca.borda at gmail.com (Rosario Borda) Date: Sat, 22 Mar 2014 21:38:43 +0100 Subject: [Haskell-beginners] Haskell code as DSL In-Reply-To: References: <532B4CC1.1050009@fuuzetsu.co.uk> <532DCA53.3000901@fuuzetsu.co.uk> Message-ID: Thank You so much for yours replies. 1. Very simple and promising. However an interesting feature of Haskell is its proximity to the natural language, especially from an educational point of view. Many important keywords (if then else, case of, type, do, where ...) aren't translatable in this approach. 2. Very interesting. Perhaps it would need a compiler, rather than a translation "words based"? 3. I followed this path with ghc, duplicating keywords to maintain compatibility with external modules. Many modules compiled, but not all due to words conflict. 4. I don't know how, any reference for Haskell? A DSL choice allow to import external modules and isolate italian code. I was wondering if there is an approach that allow to utilize the code of ghc compiler for a DSL. Many thanks for yours much appreciated help. Rosario 2014-03-22 18:56 GMT+01:00 Kim-Ee Yeoh : > > On Sun, Mar 23, 2014 at 12:37 AM, Mateusz Kowalczyk < > fuuzetsu at fuuzetsu.co.uk> wrote: > >> If you really want to go with 'translate everything' approach, what are >> you going to do about error messages? >> > > That's a good point. A fully language-native Haskell environment seems to > be sought-after here, and that's a major undertaking. > > TH, if anything, could blow up with even more error messages when fed > slightly off syntax. These are primary schoolchildren, yes? > > To summarize, the choices available include: > > 1. nativize Prelude, let children grapple with English keywords > > 2. use sed scripts or some editor feature to translate italian .ihs to .hs > before feeding into interpreter/compiler. > > 3. nativize Prelude & keywords by recompiling with necessary tweaks to the > keyword table. But errors still in English tho. > > 4. full i18n > > If GHC isn't a must, option 3 just might be a 10-minute job for hugs. > > > -- Kim-Ee > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From javran.c at gmail.com Sun Mar 23 05:51:32 2014 From: javran.c at gmail.com (Javran Cheng) Date: Sun, 23 Mar 2014 01:51:32 -0400 Subject: [Haskell-beginners] Implement semantic editor combinators In-Reply-To: References: Message-ID: On Fri, Mar 21, 2014 at 6:19 PM, Kim-Ee Yeoh wrote: > > On Fri, Mar 21, 2014 at 6:31 PM, Javran Cheng wrote: >> >> Hope you enjoy it and please feel free to give me comments and >> indicate my misconceptions. > > > A couple of things come to mind: you could > > * Ping @conal whether via email or twitter -- he's very friendly and likes > helping students. And since you worked hard at one of his blog entries, you > just might make his day! (I could also introduce you to him -- just ask.) > I'll absolutely do that! > * Have you looked at the lens library? What would the code look like using > lenses instead of SECs? A comparison would reveal tons of insights -- please > blog and share for everyone! > I tried lens few days ago to rewrite my code about "invertible functions", and to my surprise the translation was just a word-by-word conversion: https://gist.github.com/Javran/9593215 Also thanks for pointing me the idea of making comparison between lens and SEC, I'll try to play with it and see if I can extend my knowledge about it. > > -- Kim-Ee > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -- Javran (Fang) Cheng From miguel.negrao-lists at friendlyvirus.org Sun Mar 23 18:26:22 2014 From: miguel.negrao-lists at friendlyvirus.org (=?windows-1252?Q?Miguel_Negr=E3o?=) Date: Sun, 23 Mar 2014 18:26:22 +0000 Subject: [Haskell-beginners] emacs + ghc-mod + cabal repl In-Reply-To: <53298FDD.2000200@fuuzetsu.co.uk> References: <532833C6.6070505@friendlyvirus.org> <53286B1D.9030506@fuuzetsu.co.uk> <532894AE.5010206@friendlyvirus.org> <5329771A.1040100@friendlyvirus.org> <53298C1C.5010506@fuuzetsu.co.uk> <53298FDD.2000200@fuuzetsu.co.uk> Message-ID: <532F274E.9030309@friendlyvirus.org> Hi Mateus, Em 19-03-2014 12:38, Mateusz Kowalczyk escreveu: > On 19/03/14 12:22, Mateusz Kowalczyk wrote: >> On 19/03/14 10:53, Miguel Negr?o wrote: >>> Em 18-03-2014 18:47, Miguel Negr?o escreveu: >>> >>> Following that, a couple more questions: >>> >>> Is it possible to have the haddock help for functions displayed inside >>> emacs (no browser) ? >> >> Not that I know of. GHCi doesn't support it (yet, maybe it will in the >> future) and Haskell interface files don't store this information so >> various tools can't get at it. I'm not aware of any tools that read the >> Haddock interface files and give you the docs that way. If >> someone/myself decides to go through with putting the Haddock strings >> into .hi files, reading documentation in your editor might become >> possible but I wouldn't hold my breath as it is completely in the ?it'd >> be cool if we had this? stage. > > As a quick follow-up, it might be that Haddock itself will provide an > interface to its own interface files and then various tools (and GHCi) > can use that instead. Again, just ideas atm. > >> >>> How does one jump to the defition of a symbol ? >> >> I use hasktags to generate the TAGS table and then use find-tag (bound >> to M-.) to jump to things. It works fine but it does tend to screw up >> sometimes. Of course it will only work if your definition is in the >> generated table, it won't do things like jumping to definitions in the >> libraries you use etc. I imagine that you could have a massive TAGS >> table generated from all your sources but I doubt it'd scale very well >> and would be close to impossible to maintain. >> >> It'd be great if we had something like Agda, where all the source is >> available so we can jump to anything at all, but we don't. Actually I found something that does this: haskdogs (http://hackage.haskell.org/package/haskdogs-0.1). It will create tags for all the imports, it's quite fast. This kind of also solves my first question, since when navigating to the source of a function usually the documentation is on a comment over the source. I gave a try to ergoemacs, since I ctrl-c ctrl-v is in my muscle memory for some 15 years already, but it conflicts with ghc-mods shortcuts. Anyone has experience with ergoemacs-mode and ghc-mod ? best, Miguel -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 555 bytes Desc: OpenPGP digital signature URL: From ngnr63q02 at sneakemail.com Wed Mar 26 22:40:14 2014 From: ngnr63q02 at sneakemail.com (John M. Dlugosz) Date: Wed, 26 Mar 2014 17:40:14 -0500 Subject: [Haskell-beginners] Hello World Message-ID: I'm learning Haskell as a background activity, and just wanted to introduce myself and get the list subscription stuff sorted out. My primary machine runs Windows 7. I have Haskell Platform working OK including GCHi-Win, but could not get Lekseh to work. However, trying that showed me the world of Cabel, and I have yet to find an introduction/tutorial on that. The Haskell Platform comes with some libraries, but doesn't have a Cabel tool or anything I'd reconize as a repository, like Lekseh was setting up. It's said that the best feature of Perl is CPAN. I suppose Cabel is Haskell's equivalent of that, or aims to be. So, what's up with that? Starting from a blank prompt (that can run ghc successfully) now what? ?John From fuuzetsu at fuuzetsu.co.uk Thu Mar 27 01:03:07 2014 From: fuuzetsu at fuuzetsu.co.uk (Mateusz Kowalczyk) Date: Thu, 27 Mar 2014 01:03:07 +0000 Subject: [Haskell-beginners] Hello World In-Reply-To: References: Message-ID: <533378CB.8000903@fuuzetsu.co.uk> On 26/03/14 22:40, John M. Dlugosz wrote: > I'm learning Haskell as a background activity, and just wanted to introduce myself and get > the list subscription stuff sorted out. > > My primary machine runs Windows 7. I have Haskell Platform working OK including GCHi-Win, > but could not get Lekseh to work. However, trying that showed me the world of Cabel, and > I have yet to find an introduction/tutorial on that. The Haskell Platform comes with some > libraries, but doesn't have a Cabel tool or anything I'd reconize as a repository, like > Lekseh was setting up. Hi. Firstly, the tools in question are called ?Leksah? and ?Cabal? (note the ?a? as the second from last letter). Regarding your questions, there is a Cabal user guide at [1]. I don't know for sure but I imagined that Haskell Platform comes with Cabal. There are two thinks people think of when they say Cabal: there is Cabal the library and cabal-install, the binary. You can find very quick demonstration of cabal-install at [2] although I'm sure that the user guide covers it. cabal-install is the actual tool that will go out to the world and fetch packages for you. Normally to run cabal-install, we simply run the ?cabal? command. I see that Leksah is on Hackage which means that in theory, one should be able to just invoke ?cabal install leksah?. I don't know how usable it is today so if you somehow fail to install it or don't like it, I'd advise looking at getting a plugin for Haskell for your existing editor. I don't know about vim but a popular choice for Haskell is haskell-mode. See the Haskell wiki page on emacs if you're interested[3]. Hopefully Leksah works just fine for you. > It's said that the best feature of Perl is CPAN. I suppose Cabel is Haskell's equivalent > of that, or aims to be. So, what's up with that? Starting from a blank prompt (that can > run ghc successfully) now what? I can't say whether it's like CPAN but from the vague memory of using CPAN a along time ago, I think it would be, yes. > ?John > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > [1]: http://www.haskell.org/cabal/users-guide/ [2]: http://www.haskell.org/haskellwiki/Cabal-Install [3]: http://www.haskell.org/haskellwiki/Emacs -- Mateusz K. From ngnr63q02 at sneakemail.com Thu Mar 27 01:15:07 2014 From: ngnr63q02 at sneakemail.com (John M. Dlugosz) Date: Wed, 26 Mar 2014 20:15:07 -0500 Subject: [Haskell-beginners] What does the "!n" mean? Message-ID: I'm reading http://www.haskell.org/haskellwiki/IO_inside#inlinePerformIO and it shows a passage of code: write :: Int -> (Ptr Word8 -> IO ()) -> Put () write !n body = Put $ \c buf@(Buffer fp o u l) -> if n <= l then write' c fp o u l else write' (flushOld c n fp o u) (newBuffer c n) 0 0 0 where {-# NOINLINE write' #-} write' c !fp !o !u !l = -- warning: this is a tad hardcore inlinePerformIO (withForeignPtr fp (\p -> body $! (p `plusPtr` (o+u)))) `seq` c () (Buffer fp o (u+n) (l-n)) I got as far as the second line, looking things up in this index But ?write !n body = ?? I understand write is defined to be a function taking an Int and another function, but what does !n mean? I went through the 2010 Report (BTW, the PDF is useless for searching for the ! character so I used the HTML version page-by-page) and found it used as a modifier for named record fields (it says "strict" but I think it's describing non-optional). Then I went through the GHC users guide for language extensions, and found a reference in ?7.2.1 without explanation but as an example where the difference between f x = let (Foo a b, w) = ..rhs.. in ..body.. and f x = let !(Foo a b, w) = ..rhs.. in ..body.. is "you must make any such pattern-match strict". Strict pattern matching is not mentioned elsewhere nor is it in the Haskell Report, so what am I missing? I suspect that the usage I'm asking about is related. The GHC users guide also mentions it again in ?7.4.6 which I think is a reference to the same feature, ?You can use strictness annotations, in the obvious places in the constructor type? but that's for use with a completely different extension (GADT types) I also recognize the ?@? mark as naming the entire variable rather than just the parts of the pattern matched, but ?buf? is not actually used anywhere, so does it mean something different, or has other effects, or what? Thanks in advance, ?John From byorgey at seas.upenn.edu Thu Mar 27 01:18:27 2014 From: byorgey at seas.upenn.edu (Brent Yorgey) Date: Wed, 26 Mar 2014 21:18:27 -0400 Subject: [Haskell-beginners] Hello World In-Reply-To: References: Message-ID: <20140327011827.GA27570@seas.upenn.edu> On Wed, Mar 26, 2014 at 05:40:14PM -0500, John M. Dlugosz wrote: > I'm learning Haskell as a background activity, and just wanted to > introduce myself and get the list subscription stuff sorted out. > > My primary machine runs Windows 7. I have Haskell Platform working > OK including GCHi-Win, but could not get Lekseh to work. However, > trying that showed me the world of Cabel, and I have yet to find an > introduction/tutorial on that. The Haskell Platform comes with some > libraries, but doesn't have a Cabel tool or anything I'd reconize as > a repository, like Lekseh was setting up. > > It's said that the best feature of Perl is CPAN. I suppose Cabel is > Haskell's equivalent of that, or aims to be. So, what's up with > that? Starting from a blank prompt (that can run ghc successfully) > now what? In particular, the counterpart to CPAN is called Hackage, and can be found here: http://hackage.haskell.org/ With the Haskell Platform you should have a tool called 'cabal' which will actually fetch and install packages from Hackage for you (among other things). -Brent From timmelzer at gmail.com Thu Mar 27 01:23:45 2014 From: timmelzer at gmail.com (Norbert Melzer) Date: Thu, 27 Mar 2014 02:23:45 +0100 Subject: [Haskell-beginners] Hello World In-Reply-To: <20140327011827.GA27570@seas.upenn.edu> References: <20140327011827.GA27570@seas.upenn.edu> Message-ID: The last release of Leksah is about 2 years old, but emacs haskel-mode + ghc-mod is still actively maintained and developed? Even if emacs' learning curve is steep I would give it a try. I recently switched completely to it, everything started with haskell? Also I can say that sublime text 2 has a working haskell plugin. If you want to have some kind of project tree, sublime text is what you want to use, if you prefer to work from the CLI then emacs would be the one? 2014-03-27 2:18 GMT+01:00 Brent Yorgey : > On Wed, Mar 26, 2014 at 05:40:14PM -0500, John M. Dlugosz wrote: > > I'm learning Haskell as a background activity, and just wanted to > > introduce myself and get the list subscription stuff sorted out. > > > > My primary machine runs Windows 7. I have Haskell Platform working > > OK including GCHi-Win, but could not get Lekseh to work. However, > > trying that showed me the world of Cabel, and I have yet to find an > > introduction/tutorial on that. The Haskell Platform comes with some > > libraries, but doesn't have a Cabel tool or anything I'd reconize as > > a repository, like Lekseh was setting up. > > > > It's said that the best feature of Perl is CPAN. I suppose Cabel is > > Haskell's equivalent of that, or aims to be. So, what's up with > > that? Starting from a blank prompt (that can run ghc successfully) > > now what? > > In particular, the counterpart to CPAN is called Hackage, and can be found > here: > > http://hackage.haskell.org/ > > With the Haskell Platform you should have a tool called 'cabal' which > will actually fetch and install packages from Hackage for you (among > other things). > > -Brent > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuuzetsu at fuuzetsu.co.uk Thu Mar 27 01:25:15 2014 From: fuuzetsu at fuuzetsu.co.uk (Mateusz Kowalczyk) Date: Thu, 27 Mar 2014 01:25:15 +0000 Subject: [Haskell-beginners] What does the "!n" mean? In-Reply-To: References: Message-ID: <53337DFB.1030406@fuuzetsu.co.uk> On 27/03/14 01:15, John M. Dlugosz wrote: > I'm reading http://www.haskell.org/haskellwiki/IO_inside#inlinePerformIO and it shows a > passage of code: > > write :: Int -> (Ptr Word8 -> IO ()) -> Put () > write !n body = Put $ \c buf@(Buffer fp o u l) -> > if n <= l > then write' c fp o u l > else write' (flushOld c n fp o u) (newBuffer c n) 0 0 0 > > where {-# NOINLINE write' #-} > write' c !fp !o !u !l = > -- warning: this is a tad hardcore > inlinePerformIO > (withForeignPtr fp > (\p -> body $! (p `plusPtr` (o+u)))) > `seq` c () (Buffer fp o (u+n) (l-n)) > > I got as far as the second line, looking things up in this index > > > But ?write !n body = ?? > I understand write is defined to be a function taking an Int and another function, > but what does !n mean? I went through the 2010 Report (BTW, the PDF is useless for > searching for the ! character so I used the HTML version page-by-page) and found it used > as a modifier for named record fields (it says "strict" but I think it's describing > non-optional). > Then I went through the GHC users guide for language extensions, and found a reference in > ?7.2.1 without explanation but as an example where the difference between > f x = let (Foo a b, w) = ..rhs.. in ..body.. > and f x = let !(Foo a b, w) = ..rhs.. in ..body.. > is "you must make any such pattern-match strict". > Strict pattern matching is not mentioned elsewhere nor is it in the Haskell Report, so > what am I missing? I suspect that the usage I'm asking about is related. > > The GHC users guide also mentions it again in ?7.4.6 which I think is a reference to the > same feature, ?You can use strictness annotations, in the obvious places in the > constructor type? but that's for use with a completely different extension (GADT types) It is in fact a strictness annotation which forces ?n? when matching on it. It is an optimisation technique and if you're just starting out, I would not worry about it too much. I would advise against putting those on if you're not sure about the implications as they can make your performance worse. GHC can in fact often add those itself. I don't have any official reading for you but if you simply search for ?Haskell strictness? online, you should get quite a few links to Haskell wiki, the Wikibook, Stack Overflow and some blogs. > I also recognize the ?@? mark as naming the entire variable rather than just the parts of > the pattern matched, but ?buf? is not actually used anywhere, so does it mean something > different, or has other effects, or what? It just seems that someone gave it a name and then didn't use it. It does not have any extra meaning. > > Thanks in advance, > ?John > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -- Mateusz K. From byorgey at seas.upenn.edu Thu Mar 27 01:25:53 2014 From: byorgey at seas.upenn.edu (Brent Yorgey) Date: Wed, 26 Mar 2014 21:25:53 -0400 Subject: [Haskell-beginners] What does the "!n" mean? In-Reply-To: References: Message-ID: <20140327012553.GB27570@seas.upenn.edu> On Wed, Mar 26, 2014 at 08:15:07PM -0500, John M. Dlugosz wrote: > I'm reading > http://www.haskell.org/haskellwiki/IO_inside#inlinePerformIO and it > shows a passage of code: > > write :: Int -> (Ptr Word8 -> IO ()) -> Put () > write !n body = Put $ \c buf@(Buffer fp o u l) -> > if n <= l > then write' c fp o u l > else write' (flushOld c n fp o u) (newBuffer c n) 0 0 0 > > where {-# NOINLINE write' #-} > write' c !fp !o !u !l = > -- warning: this is a tad hardcore > inlinePerformIO > (withForeignPtr fp > (\p -> body $! (p `plusPtr` (o+u)))) > `seq` c () (Buffer fp o (u+n) (l-n)) > > I got as far as the second line, looking things up in this index > > > But ?write !n body = ?? > I understand write is defined to be a function taking an Int and another function, > but what does !n mean? I went through the 2010 Report (BTW, the PDF > is useless for searching for the ! character so I used the HTML > version page-by-page) and found it used as a modifier for named > record fields (it says "strict" but I think it's describing > non-optional). No, strict does not mean optional vs. non-optional. It has to do with lazy evaluation. In Haskell, by default, expressions are not evaluated until their value is actually needed. Making something strict means (to a first approximation) forcing it to be evaluated right away, whether its value will be needed or not. That is what all the exclamation points mean, both in the code you cited above and the examples you found; they can be used in a bunch of different contexts but they always have to do with strictness. Incidentally, that "IO inside" page is not particularly what I would recommend for beginners to read! It's like learning about spark plugs and oil filters on your first day of driving school. > I also recognize the ?@? mark as naming the entire variable rather > than just the parts of the pattern matched, but ?buf? is not actually > used anywhere, so does it mean something different, or has other > effects, or what? Nope, you're right, it's simply not used. Probably just an oversight on the part of whoever wrote the code. the buf@ could be deleted and it wouldn't change anything. -Brent From zhiwudazhanjiangshi at gmail.com Thu Mar 27 01:26:26 2014 From: zhiwudazhanjiangshi at gmail.com (yi lu) Date: Thu, 27 Mar 2014 09:26:26 +0800 Subject: [Haskell-beginners] What does the "!n" mean? In-Reply-To: References: Message-ID: http://www.haskell.org/ghc/docs/7.6.3/html/users_guide/bang-patterns.html Do you mean this? On Thu, Mar 27, 2014 at 9:15 AM, John M. Dlugosz wrote: > I'm reading http://www.haskell.org/haskellwiki/IO_inside#inlinePerformIOand it shows a passage of code: > > write :: Int -> (Ptr Word8 -> IO ()) -> Put () > write !n body = Put $ \c buf@(Buffer fp o u l) -> > if n <= l > then write' c fp o u l > else write' (flushOld c n fp o u) (newBuffer c n) 0 0 0 > > where {-# NOINLINE write' #-} > write' c !fp !o !u !l = > -- warning: this is a tad hardcore > inlinePerformIO > (withForeignPtr fp > (\p -> body $! (p `plusPtr` (o+u)))) > `seq` c () (Buffer fp o (u+n) (l-n)) > > I got as far as the second line, looking things up in this index < > http://hackage.haskell.org/package/base-4.6.0.1/docs/doc-index.html> > > But ?write !n body = ?? > I understand write is defined to be a function taking an Int and another > function, > but what does !n mean? I went through the 2010 Report (BTW, the PDF is > useless for searching for the ! character so I used the HTML version > page-by-page) and found it used as a modifier for named record fields (it > says "strict" but I think it's describing non-optional). > Then I went through the GHC users guide for language extensions, and found > a reference in ?7.2.1 without explanation but as an example where the > difference between > f x = let (Foo a b, w) = ..rhs.. in ..body.. > and f x = let !(Foo a b, w) = ..rhs.. in ..body.. > is "you must make any such pattern-match strict". > Strict pattern matching is not mentioned elsewhere nor is it in the > Haskell Report, so what am I missing? I suspect that the usage I'm asking > about is related. > > The GHC users guide also mentions it again in ?7.4.6 which I think is a > reference to the same feature, ?You can use strictness annotations, in the > obvious places in the constructor type? but that's for use with a > completely different extension (GADT types) > > I also recognize the ?@? mark as naming the entire variable rather than > just the parts of the pattern matched, but ?buf? is not actually used > anywhere, so does it mean something different, or has other effects, or > what? > > Thanks in advance, > ?John > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From apolishc at gmail.com Thu Mar 27 04:41:03 2014 From: apolishc at gmail.com (abraham polishchuk) Date: Wed, 26 Mar 2014 21:41:03 -0700 Subject: [Haskell-beginners] rolling my own split Message-ID: I am relatively new to Haskell, having spent the last half a decade or so developing in Ruby. I am attempting to (for the sake of exercise) implement a split function from the ground up in Haskell, and for the life of me I can not figure out why it doesn't work. Without further ado: module MyAwesomeModule where import qualified Data.Text as T outputSplit :: String -> [String] -> IO () outputSplit s tokens = print $ splitRecursive tokens s splitRecursive :: [String] -> String -> [String] splitRecursive tokens s = splitOneOf tokens s splitOneOf :: [String] -> String -> [String] splitOneOf [] s = [] splitOneOf (t:tokens) s = map (splitOneOf tokens)(map (T.unpack) (T.splitOn (T.pack t) (T.pack s))) ++ (splitOneOf tokens s) which errors out with: Couldn't match type `[Char]' with `Char' Expected type: String -> String Actual type: String -> [String] In the return type of a call of `splitOneOf' In the first argument of `map', namely `(splitOneOf tokens)' In the first argument of `(++)', namely `map (splitOneOf tokens) (map (T.unpack) (T.splitOn (T.pack t) (T.pack s)))' Failed, modules loaded: none. If anyone has any ideas, that would be awesome! And yes, I'm aware of Data.List.Split, like I said, trying to roll my own.... -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Thu Mar 27 05:32:02 2014 From: toad3k at gmail.com (David McBride) Date: Thu, 27 Mar 2014 01:32:02 -0400 Subject: [Haskell-beginners] rolling my own split In-Reply-To: References: Message-ID: You map something that returns [String] over a [String] and you get back [[String]], but your function returns [String]. Keep in mind that Strings are Lists of Chars, so ghc is a little confused about what you intended. >:t map (splitOneOf undefined) map (splitOneOf undefined) :: [String] -> [[String]] Just to make things easier, first thing I'd do is take the spliton stuff and put it in its own function. Since all it is is a T.splitOn but for strings, we'll just do that: sSplitOn :: String -> String -> [String] sSplitOn t s = map (T.unpack) ((T.pack t) `T.splitOn` (T.pack s)) And then I guessed at what you wanted out of this function, that is to run splitOn on each item? It seems like you would have gotten it if this was what you wanted, but it's all I could figure out. I'm probably wrong, but in case this is what you wanted here it is. splitOneOf :: [String] -> String -> [String] splitOneOf [] s = [] splitOneOf (t:tokens) s = (sSplitOn t s) ++ splitOneOf tokens s If this wasn't what you were looking for, it would help to have some examples of input and output. On Thu, Mar 27, 2014 at 12:41 AM, abraham polishchuk wrote: > I am relatively new to Haskell, having spent the last half a decade or so > developing in Ruby. I am attempting to (for the sake of exercise) implement > a split function from the ground up in Haskell, and for the life of me I > can not figure out why it doesn't work. Without further ado: > > > module MyAwesomeModule where > > import qualified Data.Text as T > > outputSplit :: String -> [String] -> IO () > outputSplit s tokens = print $ splitRecursive tokens s > > splitRecursive :: [String] -> String -> [String] > splitRecursive tokens s = splitOneOf tokens s > > splitOneOf :: [String] -> String -> [String] > splitOneOf [] s = [] > splitOneOf (t:tokens) s = map (splitOneOf tokens)(map (T.unpack) > (T.splitOn (T.pack t) (T.pack s))) ++ (splitOneOf tokens s) > > > which errors out with: > Couldn't match type `[Char]' with `Char' > Expected type: String -> String > Actual type: String -> [String] > In the return type of a call of `splitOneOf' > In the first argument of `map', namely `(splitOneOf tokens)' > In the first argument of `(++)', namely > `map > (splitOneOf tokens) > (map (T.unpack) (T.splitOn (T.pack t) (T.pack s)))' > Failed, modules loaded: none. > > > If anyone has any ideas, that would be awesome! And yes, I'm aware of > Data.List.Split, like I said, trying to roll my own.... > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hjgtuyl at chello.nl Thu Mar 27 07:24:30 2014 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Thu, 27 Mar 2014 08:24:30 +0100 Subject: [Haskell-beginners] Hello World In-Reply-To: References: Message-ID: On Wed, 26 Mar 2014 23:40:14 +0100, John M. Dlugosz wrote: > My primary machine runs Windows 7. I have Haskell Platform working OK > including GCHi-Win, but could not get Lekseh to work. You can download a binary from http://leksah.org/news.html#r01200 Regards, Henk-Jan van Tuyl -- Folding at home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming -- From voldermort at hotmail.com Thu Mar 27 08:01:16 2014 From: voldermort at hotmail.com (harry) Date: Thu, 27 Mar 2014 08:01:16 +0000 (UTC) Subject: [Haskell-beginners] Haskell Weekly News Message-ID: The last edition of HWN was in December. Is it defunct, or just hibernating? (This probably belongs on haskell-cafe, but for some reason it's not accepting my email.) From amy at nualeargais.ie Thu Mar 27 12:55:31 2014 From: amy at nualeargais.ie (Amy de =?utf-8?b?QnVpdGzDqWly?=) Date: Thu, 27 Mar 2014 12:55:31 +0000 (UTC) Subject: [Haskell-beginners] Haskell Weekly News References: Message-ID: I miss HWN. Especially the "quotes of the week". From alexander at plaimi.net Thu Mar 27 13:01:16 2014 From: alexander at plaimi.net (Alexander Berntsen) Date: Thu, 27 Mar 2014 14:01:16 +0100 Subject: [Haskell-beginners] Haskell Weekly News In-Reply-To: References: Message-ID: <5334211C.4060605@plaimi.net> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 On 27/03/14 13:55, Amy de Buitl?ir wrote: > I miss HWN. +1 I assume the editor doesn't have time for it any longer, but maybe they'll find it encouraging that we miss it at least. :-) - -- Alexander alexander at plaimi.net https://secure.plaimi.net/~alexander -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iF4EAREIAAYFAlM0IRwACgkQRtClrXBQc7UYEwEAqMUsZVGebIlmhNN7nj8OgL3g uaa1zGgdKjonmmaRoAwA/24yBCbkCyEQix2SyMJvomZdAnnUQaBCQggyB7pADZmf =sDi+ -----END PGP SIGNATURE----- From evohunz at gmail.com Thu Mar 27 15:21:18 2014 From: evohunz at gmail.com (Thiago Negri) Date: Thu, 27 Mar 2014 12:21:18 -0300 Subject: [Haskell-beginners] Haskell Weekly News In-Reply-To: <5334211C.4060605@plaimi.net> References: <5334211C.4060605@plaimi.net> Message-ID: +1 2014-03-27 10:01 GMT-03:00 Alexander Berntsen : > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA256 > > On 27/03/14 13:55, Amy de Buitl?ir wrote: > > I miss HWN. > +1 > > I assume the editor doesn't have time for it any longer, but maybe > they'll find it encouraging that we miss it at least. :-) > > - -- > Alexander > alexander at plaimi.net > https://secure.plaimi.net/~alexander > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v2.0.22 (GNU/Linux) > Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ > > iF4EAREIAAYFAlM0IRwACgkQRtClrXBQc7UYEwEAqMUsZVGebIlmhNN7nj8OgL3g > uaa1zGgdKjonmmaRoAwA/24yBCbkCyEQix2SyMJvomZdAnnUQaBCQggyB7pADZmf > =sDi+ > -----END PGP SIGNATURE----- > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dedgrant at gmail.com Thu Mar 27 15:24:49 2014 From: dedgrant at gmail.com (Darren Grant) Date: Thu, 27 Mar 2014 08:24:49 -0700 Subject: [Haskell-beginners] Haskell Weekly News In-Reply-To: References: <5334211C.4060605@plaimi.net> Message-ID: Indeed thank you for the HWNs of the past! I miss them too. :-) Cheers, Darren On Mar 27, 2014 8:21 AM, "Thiago Negri" wrote: > +1 > > > 2014-03-27 10:01 GMT-03:00 Alexander Berntsen : > >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA256 >> >> On 27/03/14 13:55, Amy de Buitl?ir wrote: >> > I miss HWN. >> +1 >> >> I assume the editor doesn't have time for it any longer, but maybe >> they'll find it encouraging that we miss it at least. :-) >> >> - -- >> Alexander >> alexander at plaimi.net >> https://secure.plaimi.net/~alexander >> -----BEGIN PGP SIGNATURE----- >> Version: GnuPG v2.0.22 (GNU/Linux) >> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ >> >> iF4EAREIAAYFAlM0IRwACgkQRtClrXBQc7UYEwEAqMUsZVGebIlmhNN7nj8OgL3g >> uaa1zGgdKjonmmaRoAwA/24yBCbkCyEQix2SyMJvomZdAnnUQaBCQggyB7pADZmf >> =sDi+ >> -----END PGP SIGNATURE----- >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://www.haskell.org/mailman/listinfo/beginners >> > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kd6ck at virginia.edu Thu Mar 27 15:28:01 2014 From: kd6ck at virginia.edu (ke dou) Date: Thu, 27 Mar 2014 11:28:01 -0400 Subject: [Haskell-beginners] Question about define my own typeclass Message-ID: Hi, Sorry for the spam. I am new to Haskell. I want to define my own typeclass which can convert from my own types like MyBool, MyInt, and MyString to according Haskell types. Here is my code: module Conversion where import qualified Prelude class Conversion a where conversion :: a -> b data MyBool = MyTrue | MyFalse instance Conversion MyBool where conversion MyTrue = Prelude.True conversion MyFalse =Prelude.False Here is the error message: Couldn't match expected type `b' with actual type `Prelude.Bool' `b' is a rigid type variable bound by the type signature for conversion :: MyBool -> b at Conversion.hs:11:5 Does anyone know what's wrong with my code, and how to fix it? Any hints will be appreciated !! Best, --Ke -------------- next part -------------- An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Thu Mar 27 15:36:16 2014 From: allbery.b at gmail.com (Brandon Allbery) Date: Thu, 27 Mar 2014 11:36:16 -0400 Subject: [Haskell-beginners] Question about define my own typeclass In-Reply-To: References: Message-ID: On Thu, Mar 27, 2014 at 11:28 AM, ke dou wrote: > class Conversion a where > conversion :: a -> b > b is completely unspecified here, since it's not defined as part of the typeclass. The literal meaning of this is that "the caller can request any type it pleases, and you have no way of knowing what it is". So the only possible result of `conversion` is bottom (e.g. `undefined`). This is key: it does NOT mean that `conversion` gets to specify the result type! You can't do that, except by specifying the type in the type signature. -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From kd6ck at virginia.edu Thu Mar 27 15:49:10 2014 From: kd6ck at virginia.edu (ke dou) Date: Thu, 27 Mar 2014 11:49:10 -0400 Subject: [Haskell-beginners] Question about define my own typeclass In-Reply-To: References: Message-ID: Thanks for your reply. Yes, I understand that if I specify the 'b' to 'Prelude.Bool', it should work, but what if I also want use the typeclass Conversion to convert other types other than MyBool, like MyInt, or MyString? --Ke On Thu, Mar 27, 2014 at 11:36 AM, Brandon Allbery wrote: > On Thu, Mar 27, 2014 at 11:28 AM, ke dou wrote: > >> class Conversion a where >> conversion :: a -> b >> > > b is completely unspecified here, since it's not defined as part of the > typeclass. The literal meaning of this is that "the caller can request any > type it pleases, and you have no way of knowing what it is". So the only > possible result of `conversion` is bottom (e.g. `undefined`). > > This is key: it does NOT mean that `conversion` gets to specify the result > type! You can't do that, except by specifying the type in the type > signature. > > -- > brandon s allbery kf8nh sine nomine > associates > allbery.b at gmail.com > ballbery at sinenomine.net > unix, openafs, kerberos, infrastructure, xmonad > http://sinenomine.net > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From leilmyxwz at gmail.com Thu Mar 27 15:50:28 2014 From: leilmyxwz at gmail.com (bruce li) Date: Thu, 27 Mar 2014 11:50:28 -0400 Subject: [Haskell-beginners] What to do next? In-Reply-To: <532B6869.1020100@gmail.com> References: <532B6869.1020100@gmail.com> Message-ID: Thanks for the exercises. I think I've finished all exercises except the last 2 projects. But here are some questions regarding the exercises: 1. The layout of the typeclasses looks a bit different from Haskell, like splitting applicative functor into apply and applicative. I wonder you could tell me the reason. 2. How to write cooler code like lift2 ((++) =<<) preillion postillion? How could I make such usage a habit? Thanks. 2014-03-20 18:15 GMT-04:00 Tony Morris : > I teach FP for a living for an organisation called NICTA. This is the > material I use primarily https://github.com/NICTA/course > > If you can do the easy stuff, fine. For example, > https://github.com/NICTA/course/blob/master/src/Course/List.hs > https://github.com/NICTA/course/blob/master/src/Course/ListZipper.hs > https://github.com/NICTA/course/blob/master/src/Course/StateT.hs > > If you want it a bit harder: > https://github.com/NICTA/course/blob/master/src/Course/Parser.hs > https://github.com/NICTA/course/blob/master/src/Course/JsonParser.hs > https://github.com/NICTA/course/blob/master/src/Course/Cheque.hs > > But if you can do any of these, then I would say you are not a beginner > anymore: > > https://github.com/NICTA/course/blob/master/projects/TicTacToe/TicTacToe.markdown > > https://github.com/NICTA/course/blob/master/projects/NetworkServer/NetworkServer.markdown > > > > On 21/03/14 04:17, bruce li wrote: > > Hi, there, > I'm relatively new to Haskell...well... I mean I haven't done anything I > believe truely in Haskell. I have gone through materials like Learn You a > Haskell for Real Good, Real World Haskell, most chapters in Haskell > Wikibook, Write Yourself Scheme in 48 Hours, Algorithms: A Functional > Approach and other materials in Haskell Wiki. > > *But... what I feel is that I'm not confident while writing Haskell > code.* Having gone through all those materials with "magic", I always > feel I'm writing stupid code and there must be more elegant way... And... > what's worse, I feel guilty while using IO monad but I simply cannot avoid > it, like when I try to write code generator for a toy compiler, I need to > keep state of the registers, which I need IORef... Then I feel its not pure > anymore but I don't know how to get around it. > > I'm wondering if anyone else shares this kind of feeling and what should > I do next? Could anyone suggest any project to get hands on experience with > Haskell? > > Another question is that the deeper digging into functional algorithms > design (reading the book Pearls of Functional Algorithm Design), the more > ignorant I feel. So how do I make up the basics like fold law, list > induction etc. Any suggested reading materials? > > Well.. I think that's a lot question. Thanks for your patience and your > kind help. > > > _______________________________________________ > Beginners mailing listBeginners at haskell.orghttp://www.haskell.org/mailman/listinfo/beginners > > > > -- > Tony Morrishttp://tmorris.net/ > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From zlatan.todoric at gmail.com Thu Mar 27 16:21:57 2014 From: zlatan.todoric at gmail.com (Zlatan Todoric) Date: Thu, 27 Mar 2014 17:21:57 +0100 Subject: [Haskell-beginners] Haskell Weekly News In-Reply-To: References: <5334211C.4060605@plaimi.net> Message-ID: I am new on list but I would certainly like to see HWN :) On Thu, Mar 27, 2014 at 4:24 PM, Darren Grant wrote: > Indeed thank you for the HWNs of the past! I miss them too. :-) > > Cheers, > Darren > On Mar 27, 2014 8:21 AM, "Thiago Negri" wrote: > >> +1 >> >> >> 2014-03-27 10:01 GMT-03:00 Alexander Berntsen : >> >>> -----BEGIN PGP SIGNED MESSAGE----- >>> Hash: SHA256 >>> >>> On 27/03/14 13:55, Amy de Buitl?ir wrote: >>> > I miss HWN. >>> +1 >>> >>> I assume the editor doesn't have time for it any longer, but maybe >>> they'll find it encouraging that we miss it at least. :-) >>> >>> - -- >>> Alexander >>> alexander at plaimi.net >>> https://secure.plaimi.net/~alexander >>> -----BEGIN PGP SIGNATURE----- >>> Version: GnuPG v2.0.22 (GNU/Linux) >>> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ >>> >>> iF4EAREIAAYFAlM0IRwACgkQRtClrXBQc7UYEwEAqMUsZVGebIlmhNN7nj8OgL3g >>> uaa1zGgdKjonmmaRoAwA/24yBCbkCyEQix2SyMJvomZdAnnUQaBCQggyB7pADZmf >>> =sDi+ >>> -----END PGP SIGNATURE----- >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://www.haskell.org/mailman/listinfo/beginners >>> >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://www.haskell.org/mailman/listinfo/beginners >> >> > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -- Please while sending me text documents pay attention that they are by ISO standard that is in .odt format (For sending other types of documents please also refer to ISO/Open standars). Its not the COST, its the VALUE! -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuuzetsu at fuuzetsu.co.uk Thu Mar 27 16:36:12 2014 From: fuuzetsu at fuuzetsu.co.uk (Mateusz Kowalczyk) Date: Thu, 27 Mar 2014 16:36:12 +0000 Subject: [Haskell-beginners] Question about define my own typeclass In-Reply-To: References: Message-ID: <5334537C.9000002@fuuzetsu.co.uk> On 27/03/14 15:49, ke dou wrote: > Thanks for your reply. > > Yes, I understand that if I specify the 'b' to 'Prelude.Bool', it should > work, but what if I also want use the typeclass Conversion to convert other > types other than MyBool, like MyInt, or MyString? > > --Ke > > On Thu, Mar 27, 2014 at 11:36 AM, Brandon Allbery wrote: > >> On Thu, Mar 27, 2014 at 11:28 AM, ke dou wrote: >> >>> class Conversion a where >>> conversion :: a -> b >>> >> >> b is completely unspecified here, since it's not defined as part of the >> typeclass. The literal meaning of this is that "the caller can request any >> type it pleases, and you have no way of knowing what it is". So the only >> possible result of `conversion` is bottom (e.g. `undefined`). >> >> This is key: it does NOT mean that `conversion` gets to specify the result >> type! You can't do that, except by specifying the type in the type >> signature. >> >> -- >> brandon s allbery kf8nh sine nomine >> associates >> allbery.b at gmail.com >> ballbery at sinenomine.net >> unix, openafs, kerberos, infrastructure, xmonad >> http://sinenomine.net >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://www.haskell.org/mailman/listinfo/beginners >> >> > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > This post is Literate Haskell. You can specify which type you can coerce to by having the typeclass also specify ?b?. To have more than one type parameter, you'll need the MultiParamTypeClasses language extension. Ignore FunctionalDependencies for now. > {-# LANGUAGE FunctionalDependencies #-} > {-# LANGUAGE MultiParamTypeClasses #-} > {-# LANGUAGE UnicodeSyntax #-} > module C where First we define our own Bool for demonstration purposes. > data MyBool = MyTrue | MyFalse We define the class that also specifies ?b? as follows. > class SimpleCoercible a b where > coerceSimple ? a ? b We can now achieve what you want: we can state that ?a? cana be coerced into ?b?. Here we state that we can convert to Haskell's Bool. > instance SimpleCoercible MyBool Bool where > coerceSimple MyTrue = True > coerceSimple MyFalse = False This works fine: *C> coerceSimple MyTrue :: Bool True Note that I had to say what output type I wanted here because I'm not using it in a context that GHC could use to infer it. Just because there's only a single instance does not matter as anyone could come around and add a new instance. In fact, let's define one more just to show that you can do it. Let's go with the old 0 is True and 1 is False. > instance SimpleCoercible MyBool Integer where > coerceSimple MyTrue = 0 > coerceSimple MyFalse = 1 As you can see below, it all works great: *C> coerceSimple MyTrue :: Integer 0 *C> coerceSimple MyTrue :: Bool True Now for something a bit out of scope of the question: Now what if we wanted to only have a single possible mapping? Say, we only want MyBool to be coercible to Bool and nothing else? We can use FunctionalDependencies language extension. I recommend you look it up if you're interested, here's an example: > class CoercibleOneWay a b | a ? b where > coerceOneWay ? a ? b > > instance CoercibleOneWay MyBool Bool where > coerceOneWay MyTrue = True > coerceOneWay MyFalse = False You might wonder if there's an advantage to doing such a thing. Well, yes, GHC now always knows what the output type (b) should be just by looking by the input type (a): *C> :t coerceOneWay MyTrue coerceOneWay MyTrue :: Bool Note that this is not the case with our previous definition! GHC doesn't know exactly which ?b? we want: *C> :t coerceSimple MyTrue coerceSimple MyTrue :: SimpleCoercible MyBool b => b Can we do more than this? What if we wanted to be able to coerce the types the other way too? We could write an instance for ?CoercibleOneWay Bool MyBool | b ? a? but that's unwieldy. We can instead have a single type class which can take us both ways: > class Coercible a b | a ? b, b ? a where > coerceTo ? a ? b > coerceFrom ? b ? a > > instance Coercible MyBool Bool where > coerceTo MyTrue = True > coerceTo MyFalse = False > > coerceFrom True = MyTrue > coerceFrom False = MyFalse This now lets us convert between MyBool and Bool freely: *C> :t coerceTo MyTrue coerceTo MyTrue :: Bool *C> :t coerceFrom True coerceFrom True :: MyBool With this you can model 1-to-1 mapping between your types and built-in types. Note that another approach would simply be to add an instance for ?CoercibleOneWay Bool MyBool?. A nice thing about this approach is that you can use the overloaded function name: > instance CoercibleOneWay Bool MyBool where > coerceOneWay True = MyTrue > coerceOneWay False = MyFalse *C> :t coerceOneWay True coerceOneWay True :: MyBool *C> :t coerceOneWay MyTrue coerceOneWay MyTrue :: Bool I think it's a matter of preference as to which way you go. -- Mateusz K. From ngnr63q02 at sneakemail.com Thu Mar 27 19:32:50 2014 From: ngnr63q02 at sneakemail.com (John M. Dlugosz) Date: Thu, 27 Mar 2014 14:32:50 -0500 Subject: [Haskell-beginners] What does the "!n" mean? In-Reply-To: References: Message-ID: On 3/26/2014 8:26 PM, yi lu wrote: > http://www.haskell.org/ghc/docs/7.6.3/html/users_guide/bang-patterns.html > > Do you mean this? Thanks! I missed it when scanning through the GHC docs. From ngnr63q02 at sneakemail.com Thu Mar 27 19:58:46 2014 From: ngnr63q02 at sneakemail.com (John M. Dlugosz) Date: Thu, 27 Mar 2014 14:58:46 -0500 Subject: [Haskell-beginners] Cabal gives error Message-ID: When running cabal, it tells me Note: there is a new version of cabal-install available. To upgrade, run: cabal install cabal-install And when I do that, it does a bunch of stuff and then [68 of 70] Compiling Distribution.Simple.Bench ( E:\Temp\Cabal-1.18.1.3-7348\Cabal-1.18.1.3\Distribution\Simple\Bench.hs, E:\Temp\Cabal-1.18.1.3-7348\Cabal-1.18 .1.3\dist\setup\Distribution\Simple\Bench.o ) [69 of 70] Compiling Distribution.Simple ( E:\Temp\Cabal-1.18.1.3-7348\Cabal-1.18.1.3\Distribution\Simple.hs, E:\Temp\Cabal-1.18.1.3-7348\Cabal-1.18.1.3\dist\setup\Distribution\Simple.o ) [70 of 70] Compiling Main ( E:\Temp\Cabal-1.18.1.3-7348\Cabal-1.18.1.3\Setup.hs, E:\Temp\Cabal-1.18.1.3-7348\Cabal-1.18.1.3\dist\setup\Main.o ) Linking E:\Temp\Cabal-1.18.1.3-7348\Cabal-1.18.1.3\dist\setup\setup.exe ... Configuring Cabal-1.18.1.3... setup.exe: does not exist Failed to install Cabal-1.18.1.3 cabal: Error: some packages failed to install: Cabal-1.18.1.3 failed during the configure step. The exception was: ExitFailure 1 cabal-install-1.18.0.3 depends on Cabal-1.18.1.3 which failed to install. [C:\Program Files (x86)\Haskell-Platform] This is, as I recall, where I got stuck trying to get a newer Leksah installed. Upon finishing, it deletes the temp directory tree, so I can't see if there's anything obviously strange with the file it produced. How do I troubleshoot this? From ngnr63q02 at sneakemail.com Thu Mar 27 20:51:22 2014 From: ngnr63q02 at sneakemail.com (John M. Dlugosz) Date: Thu, 27 Mar 2014 15:51:22 -0500 Subject: [Haskell-beginners] =?utf-8?q?Unicode_Fanatic_=E2=80=94_How_to_us?= =?utf-8?q?e=3F?= Message-ID: I love using non-ASCII characters! Even my name, D?ugosz, needs Latin-2. My wife's name, ?, doesn't even use Latin characters. I've inserted thousands of em and en dashes in Wikipedia and can easily type at least three kinds of blank space. When I was in a college class on programming theory, we studied Backus?s FP System and I corresponded with John Backus to ask a question the prof couldn't handle, and he sent me the TeX definitions he used, so my homework really did match the appearance of the textbook. But that's another story. I managed to get my name in the Unicode 3 hardcopy book. So, I relish the ability to use proper math symbols in Haskell. Here is an example of what I've tried: {-# LANGUAGE UnicodeSyntax #-} import Prelude.Unicode f x y = x?y result = f ? id -- problem = ? True Is the UnicodeSyntax pragma a different mechanism than the modules? Do I need to state both, or do they clash, or work together, or what? Do I need to list all the individual modules (up to 12 of them) as needed (see http://hackage.haskell.org/package/base-unicode-symbols) or can they be brought in as one easy chunk, as the package itself is one thing? The compiler does not like the ? symbol, with or without the pragma. http://hackage.haskell.org/package/base-unicode-symbols-0.2.2.4/docs/Prelude-Unicode.html clearly shows it (the first one!) and it appears in the module source so presumably it didn't choke there. I recall seeing that it is one of the "problematic" symbols but GHC has some extensions. OTOH, I read that ? can?t be made to work, which is sad. Maybe ? (which is a symbol) can be used instead? From toad3k at gmail.com Thu Mar 27 21:13:38 2014 From: toad3k at gmail.com (David McBride) Date: Thu, 27 Mar 2014 17:13:38 -0400 Subject: [Haskell-beginners] Unicode Fanatic -- How to use? In-Reply-To: References: Message-ID: I think the problem is that ? is unary. You can use problem = (?) True. I'm not sure that there isn't a way around this. On Thu, Mar 27, 2014 at 4:51 PM, John M. Dlugosz wrote: > I love using non-ASCII characters! Even my name, D?ugosz, needs Latin-2. > My wife's name, ?, doesn't even use Latin characters. I've inserted > thousands of em and en dashes in Wikipedia and can easily type at least > three kinds of blank space. > > When I was in a college class on programming theory, we studied Backus?s > FP System and I corresponded with John Backus to ask a question the prof > couldn't handle, and he sent me the TeX definitions he used, so my homework > really did match the appearance of the textbook. But that's another story. > I managed to get my name in the Unicode 3 hardcopy book. > > So, I relish the ability to use proper math symbols in Haskell. > > Here is an example of what I've tried: > > {-# LANGUAGE UnicodeSyntax #-} > > import Prelude.Unicode > > f x y = x?y > > result = f ? id > > -- problem = ? True > > Is the UnicodeSyntax pragma a different mechanism than the modules? Do I > need to state both, or do they clash, or work together, or what? > > Do I need to list all the individual modules (up to 12 of them) as needed > (see http://hackage.haskell.org/package/base-unicode-symbols) or can they > be brought in as one easy chunk, as the package itself is one thing? > > The compiler does not like the ? symbol, with or without the pragma. > http://hackage.haskell.org/package/base-unicode-symbols- > 0.2.2.4/docs/Prelude-Unicode.html > clearly shows it (the first one!) and it appears in the module source so > presumably it didn't choke there. I recall seeing that it is one of the > "problematic" symbols but GHC has some extensions. > > OTOH, I read that ? can?t be made to work, which is sad. Maybe ? (which > is a symbol) can be used instead? > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kd6ck at virginia.edu Thu Mar 27 21:15:52 2014 From: kd6ck at virginia.edu (ke dou) Date: Thu, 27 Mar 2014 17:15:52 -0400 Subject: [Haskell-beginners] Question about define my own typeclass In-Reply-To: <5334537C.9000002@fuuzetsu.co.uk> References: <5334537C.9000002@fuuzetsu.co.uk> Message-ID: Thanks a lot! That really helps me understand the typeclass and solve my problem. Best, Ke On Thu, Mar 27, 2014 at 12:36 PM, Mateusz Kowalczyk wrote: > On 27/03/14 15:49, ke dou wrote: > > Thanks for your reply. > > > > Yes, I understand that if I specify the 'b' to 'Prelude.Bool', it should > > work, but what if I also want use the typeclass Conversion to convert > other > > types other than MyBool, like MyInt, or MyString? > > > > --Ke > > > > On Thu, Mar 27, 2014 at 11:36 AM, Brandon Allbery >wrote: > > > >> On Thu, Mar 27, 2014 at 11:28 AM, ke dou wrote: > >> > >>> class Conversion a where > >>> conversion :: a -> b > >>> > >> > >> b is completely unspecified here, since it's not defined as part of the > >> typeclass. The literal meaning of this is that "the caller can request > any > >> type it pleases, and you have no way of knowing what it is". So the only > >> possible result of `conversion` is bottom (e.g. `undefined`). > >> > >> This is key: it does NOT mean that `conversion` gets to specify the > result > >> type! You can't do that, except by specifying the type in the type > >> signature. > >> > >> -- > >> brandon s allbery kf8nh sine nomine > >> associates > >> allbery.b at gmail.com > >> ballbery at sinenomine.net > >> unix, openafs, kerberos, infrastructure, xmonad > >> http://sinenomine.net > >> > >> _______________________________________________ > >> Beginners mailing list > >> Beginners at haskell.org > >> http://www.haskell.org/mailman/listinfo/beginners > >> > >> > > > > > > > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://www.haskell.org/mailman/listinfo/beginners > > > > This post is Literate Haskell. > > You can specify which type you can coerce to by having the typeclass > also specify ?b?. > > To have more than one type parameter, you'll need the MultiParamTypeClasses > language extension. Ignore FunctionalDependencies for now. > > > {-# LANGUAGE FunctionalDependencies #-} > > {-# LANGUAGE MultiParamTypeClasses #-} > > {-# LANGUAGE UnicodeSyntax #-} > > module C where > > First we define our own Bool for demonstration purposes. > > > data MyBool = MyTrue | MyFalse > > We define the class that also specifies ?b? as follows. > > > class SimpleCoercible a b where > > coerceSimple ? a ? b > > We can now achieve what you want: we can state that ?a? cana be > coerced into ?b?. Here we state that we can convert to Haskell's Bool. > > > instance SimpleCoercible MyBool Bool where > > coerceSimple MyTrue = True > > coerceSimple MyFalse = False > > This works fine: > > *C> coerceSimple MyTrue :: Bool > True > > Note that I had to say what output type I wanted here because I'm not > using it > in a context that GHC could use to infer it. Just because there's only a > single > instance does not matter as anyone could come around and add a new > instance. In > fact, let's define one more just to show that you can do it. Let's go > with the > old 0 is True and 1 is False. > > > instance SimpleCoercible MyBool Integer where > > coerceSimple MyTrue = 0 > > coerceSimple MyFalse = 1 > > As you can see below, it all works great: > > *C> coerceSimple MyTrue :: Integer > 0 > *C> coerceSimple MyTrue :: Bool > True > > > Now for something a bit out of scope of the question: > > Now what if we wanted to only have a single possible mapping? Say, we > only want > MyBool to be coercible to Bool and nothing else? We can use > FunctionalDependencies language extension. I recommend you look it up if > you're > interested, here's an example: > > > > class CoercibleOneWay a b | a ? b where > > coerceOneWay ? a ? b > > > > instance CoercibleOneWay MyBool Bool where > > coerceOneWay MyTrue = True > > coerceOneWay MyFalse = False > > You might wonder if there's an advantage to doing such a thing. Well, > yes, GHC > now always knows what the output type (b) should be just by looking by > the input > type (a): > > *C> :t coerceOneWay MyTrue > coerceOneWay MyTrue :: Bool > > Note that this is not the case with our previous definition! GHC doesn't > know > exactly which ?b? we want: > > *C> :t coerceSimple MyTrue > coerceSimple MyTrue :: SimpleCoercible MyBool b => b > > > Can we do more than this? What if we wanted to be able to coerce the > types the > other way too? We could write an instance for > ?CoercibleOneWay Bool MyBool | b ? a? but that's unwieldy. We can > instead have > a single type class which can take us both ways: > > > class Coercible a b | a ? b, b ? a where > > coerceTo ? a ? b > > coerceFrom ? b ? a > > > > instance Coercible MyBool Bool where > > coerceTo MyTrue = True > > coerceTo MyFalse = False > > > > coerceFrom True = MyTrue > > coerceFrom False = MyFalse > > This now lets us convert between MyBool and Bool freely: > > *C> :t coerceTo MyTrue > coerceTo MyTrue :: Bool > *C> :t coerceFrom True > coerceFrom True :: MyBool > > With this you can model 1-to-1 mapping between your types and built-in > types. > > Note that another approach would simply be to add an instance for > ?CoercibleOneWay Bool MyBool?. A nice thing about this approach is that > you can > use the overloaded function name: > > > instance CoercibleOneWay Bool MyBool where > > coerceOneWay True = MyTrue > > coerceOneWay False = MyFalse > > *C> :t coerceOneWay True > coerceOneWay True :: MyBool > *C> :t coerceOneWay MyTrue > coerceOneWay MyTrue :: Bool > > I think it's a matter of preference as to which way you go. > > > -- > Mateusz K. > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From byorgey at seas.upenn.edu Thu Mar 27 21:26:45 2014 From: byorgey at seas.upenn.edu (Brent Yorgey) Date: Thu, 27 Mar 2014 17:26:45 -0400 Subject: [Haskell-beginners] =?utf-8?q?Unicode_Fanatic_=E2=80=94_How_to_us?= =?utf-8?q?e=3F?= In-Reply-To: References: Message-ID: <20140327212645.GA7387@seas.upenn.edu> Have you seen http://www.haskell.org/haskellwiki/Unicode-symbols ? I think it answers most of your questions. In brief: the UnicodeSyntax pragma allows various non-ASCII symbols to be used in place of built-in Haskell syntax (such as ? in place of forall). The base-unicode-symbols defines non-ASCII synonyms for common functions defined in the 'base' package. The two are entirely orthogonal: the new names for things in 'base' have nothing to do with Haskell syntax; conversely, Haskell with no extensions already supports arbitrary Unicode in identifier names. -Brent On Thu, Mar 27, 2014 at 03:51:22PM -0500, John M. Dlugosz wrote: > I love using non-ASCII characters! Even my name, D?ugosz, needs > Latin-2. My wife's name, ?, doesn't even use Latin characters. > I've inserted thousands of em and en dashes in Wikipedia and can > easily type at least three kinds of blank space. > > When I was in a college class on programming theory, we studied > Backus?s FP System and I corresponded with John Backus to ask a > question the prof couldn't handle, and he sent me the TeX definitions > he used, so my homework really did match the appearance of the > textbook. But that's another story. I managed to get my name in the > Unicode 3 hardcopy book. > > So, I relish the ability to use proper math symbols in Haskell. > > Here is an example of what I've tried: > > {-# LANGUAGE UnicodeSyntax #-} > > import Prelude.Unicode > > f x y = x?y > > result = f ? id > > -- problem = ? True > > Is the UnicodeSyntax pragma a different mechanism than the modules? > Do I need to state both, or do they clash, or work together, or what? > > Do I need to list all the individual modules (up to 12 of them) as > needed (see http://hackage.haskell.org/package/base-unicode-symbols) > or can they be brought in as one easy chunk, as the package itself is > one thing? > > The compiler does not like the ? symbol, with or without the pragma. > http://hackage.haskell.org/package/base-unicode-symbols-0.2.2.4/docs/Prelude-Unicode.html > clearly shows it (the first one!) and it appears in the module source > so presumably it didn't choke there. I recall seeing that it is one > of the "problematic" symbols but GHC has some extensions. > > OTOH, I read that ? can?t be made to work, which is sad. Maybe ? > (which is a symbol) can be used instead? > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > From hjgtuyl at chello.nl Thu Mar 27 22:06:02 2014 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Thu, 27 Mar 2014 23:06:02 +0100 Subject: [Haskell-beginners] What to do next? In-Reply-To: References: <532B6869.1020100@gmail.com> Message-ID: On Thu, 27 Mar 2014 16:50:28 +0100, bruce li wrote: > 2. How to write cooler code like lift2 ((++) =<<) preillion postillion? > How could I make such usage a habit? I think it is better to not make this a habit; such coding is both hard to write and read. IMHO a better way to write this, is using a list comprehension: [x ++ y | x <- preillion, y <- postillion] I simple cases, point-free style[0] can be an advantage, however. Regards, Henk-Jan van Tuyl [0] http://www.haskell.org/haskellwiki/Pointfree -- Folding at home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming -- From hjgtuyl at chello.nl Thu Mar 27 23:36:01 2014 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Fri, 28 Mar 2014 00:36:01 +0100 Subject: [Haskell-beginners] What to do next? In-Reply-To: References: <532B6869.1020100@gmail.com> Message-ID: On Thu, 27 Mar 2014 23:06:02 +0100, Henk-Jan van Tuyl wrote: > On Thu, 27 Mar 2014 16:50:28 +0100, bruce li wrote: > >> 2. How to write cooler code like lift2 ((++) =<<) preillion postillion? >> How could I make such usage a habit? > > I think it is better to not make this a habit; such coding is both hard > to write and read. IMHO a better way to write this, is using a list > comprehension: > [x ++ y | x <- preillion, y <- postillion] Studying a bit better on the example, I see that I misinterpreted it; this show how hard it is to read. Regards, Henk-Jan van Tuyl -- Folding at home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming -- From michael at orlitzky.com Fri Mar 28 01:10:50 2014 From: michael at orlitzky.com (Michael Orlitzky) Date: Thu, 27 Mar 2014 21:10:50 -0400 Subject: [Haskell-beginners] Question about define my own typeclass In-Reply-To: References: Message-ID: <5334CC1A.1010305@orlitzky.com> On 03/27/2014 11:28 AM, ke dou wrote: > Hi, > > Sorry for the spam. > > I am new to Haskell. > I want to define my own typeclass which can convert from my own types > like MyBool, MyInt, and MyString to according Haskell types. As you've seen, this is actually a hard problem and it needs some of GHC's more advanced machinery. Mateusz's solution uses FunctionalDependencies; there is a similar extension called TypeFamilies which allow you to do many of the same things with (IMO) a nicer syntax. You can think of TypeFamilies as allowing you to define functions between types. And then, just like you can define functions between values in a typeclass, you can define functions between types. This allows you to say (in the instance declaration) which return type goes with MyBool, MyInt, etc. Here is a simple modification of your program (2.5 lines?) using type families. In the type class definition, the "type Return a..." line means that each instance declaration needs to define a type associated 'a' called 'Return a'. Then in the type signature of 'conversion', we can use that type, solving the problem that others have pointed out. > {-# LANGUAGE TypeFamilies #-} > > module Conversion where > > import qualified Prelude > > class Conversion a where > type Return a :: * > conversion :: a -> (Return a) > > data MyBool = MyTrue | MyFalse > > instance Conversion MyBool where > type Return MyBool = Prelude.Bool > conversion MyTrue = Prelude.True > conversion MyFalse = Prelude.False From dennis.raddle at gmail.com Fri Mar 28 01:35:11 2014 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Thu, 27 Mar 2014 18:35:11 -0700 Subject: [Haskell-beginners] typeclass Message-ID: If I write a function like this: f (x1,y1) (x2,y2) = (x1++x2,y1++y2) My understanding of typeclasses is just developing, but I notice this is a bit like "lifting" (++) into a tuple. Maybe there is some existing typeclass and a 2-tuple is already an instance of it? Like arrow? D -------------- next part -------------- An HTML attachment was scrubbed... URL: From nishantgeek at gmail.com Fri Mar 28 05:30:38 2014 From: nishantgeek at gmail.com (Nishant) Date: Fri, 28 Mar 2014 11:00:38 +0530 Subject: [Haskell-beginners] Array/Vector like DS in haskell Message-ID: Hi, Can someone elaborate on how to create a DS which acts like an array or vector and has same time complexity ? A list though can act like array but getting value at index i is linear time but in actual array it is constant. Regards. Nishant -------------- next part -------------- An HTML attachment was scrubbed... URL: From ngnr63q02 at sneakemail.com Fri Mar 28 05:54:03 2014 From: ngnr63q02 at sneakemail.com (John M. Dlugosz) Date: Fri, 28 Mar 2014 00:54:03 -0500 Subject: [Haskell-beginners] What is operator :| ? Message-ID: http://www.haskell.org/haskellwiki/Typeclassopedia under ?8.1, sconcat = sconcat (a :| as) = go a as where What is the meaning of :| ? I see it is really in the cited module source, not a typo on the page. More generally, is there some effective way to search for non-alphabetical Haskell things? Google just ignores the "punctuation". From tmorris at tmorris.net Fri Mar 28 06:41:26 2014 From: tmorris at tmorris.net (Tony Morris) Date: Fri, 28 Mar 2014 16:41:26 +1000 Subject: [Haskell-beginners] What is operator :| ? In-Reply-To: References: Message-ID: It is the constructor for a non-empty list (Data.List.NonEmpty). http://hackage.haskell.org/package/semigroups-0.12.2/docs/Data-List-NonEmpty.html On Fri, Mar 28, 2014 at 3:54 PM, John M. Dlugosz wrote: > http://www.haskell.org/haskellwiki/Typeclassopedia under ?8.1, > > sconcat = sconcat (a :| as) = go a as where > > What is the meaning of :| ? > I see it is really in the cited module source, not a typo on the page. > > More generally, is there some effective way to search for non-alphabetical > Haskell things? Google just ignores the "punctuation". > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From karl at karlv.net Fri Mar 28 06:48:49 2014 From: karl at karlv.net (Karl Voelker) Date: Thu, 27 Mar 2014 23:48:49 -0700 Subject: [Haskell-beginners] What is operator :| ? In-Reply-To: References: Message-ID: <1395989329.2553.99909509.15479C7B@webmail.messagingengine.com> On Thu, Mar 27, 2014, at 10:54 PM, John M. Dlugosz wrote: > More generally, is there some effective way to search for > non-alphabetical Haskell things? > Google just ignores the "punctuation". For that, you can use Hayoo. http://holumbus.fh-wedel.de/hayoo/hayoo.html -Karl From fa-ml at ariis.it Fri Mar 28 06:48:28 2014 From: fa-ml at ariis.it (Francesco Ariis) Date: Fri, 28 Mar 2014 07:48:28 +0100 Subject: [Haskell-beginners] What is operator :| ? In-Reply-To: References: Message-ID: <20140328064828.GA6987@x60s.casa> On Fri, Mar 28, 2014 at 12:54:03AM -0500, John M. Dlugosz wrote: > More generally, is there some effective way to search for > non-alphabetical Haskell things? Google just ignores the > "punctuation". > You can find :| on Hayoo [1], the other handy place where to look for APIs stuff being Hoogle [2] (Hoogle is more focused on 'standard' Haskell libraries, Hayoo searches in all Hackage, both have their usefulness). >From there, if I need to search, say, a blog post, I will refer to the name of the typeclass/module/data and feed it to a search engine (so in this case "data NonEmpty etc. etc."). Apparently Google ignores punctuation in most cases [3]. Back to the original question > What is the meaning of :| ? Clicking on the first occurrence in Hoogle brings me to Data.List.NonEmpty, where the specific operator is listed as the lone constructor of |data NonEmpty|. If the conspicuous name were not enough, checking the code: data NonEmpty a = a :| [a] we can see this looks like a list without the empty-list constructor. Does that answer your question? [1] http://holumbus.fh-wedel.de/hayoo/hayoo.html#0:%3A| [2] http://www.haskell.org/hoogle/ [3] https://support.google.com/websearch/answer/2466433 [4] http://hackage.haskell.org/package/semigroups-0.12.2/docs/Data-List-NonEmpty.html#v::-124- From ngnr63q02 at sneakemail.com Fri Mar 28 06:58:11 2014 From: ngnr63q02 at sneakemail.com (John M. Dlugosz) Date: Fri, 28 Mar 2014 01:58:11 -0500 Subject: [Haskell-beginners] What is operator :| ? In-Reply-To: References: Message-ID: On 3/28/2014 1:41 AM, Tony Morris wrote: > It is the constructor for a non-empty list (Data.List.NonEmpty). > > http://hackage.haskell.org/package/semigroups-0.12.2/docs/Data-List-NonEmpty.html > Interesting? this is the page I had found: http://www.haskell.org/haskellwiki/Non-empty_list So why do we need both :| and <| (or cons) ? From ngnr63q02 at sneakemail.com Fri Mar 28 06:59:26 2014 From: ngnr63q02 at sneakemail.com (John M. Dlugosz) Date: Fri, 28 Mar 2014 01:59:26 -0500 Subject: [Haskell-beginners] Array/Vector like DS in haskell In-Reply-To: References: Message-ID: On 3/28/2014 12:30 AM, Nishant wrote: > Can someone elaborate on how to create a DS which acts like an array or vector and has > same time complexity ? > > > A list though can act like array but getting value at index i is linear time but in actual > array it is constant. I was just reading http://www.haskell.org/haskellwiki/Arrays From fa-ml at ariis.it Fri Mar 28 07:21:46 2014 From: fa-ml at ariis.it (Francesco Ariis) Date: Fri, 28 Mar 2014 08:21:46 +0100 Subject: [Haskell-beginners] What is operator :| ? In-Reply-To: References: Message-ID: <20140328072146.GA29495@x60s.casa> On Fri, Mar 28, 2014 at 01:58:11AM -0500, John M. Dlugosz wrote: > On 3/28/2014 1:41 AM, Tony Morris wrote: > >It is the constructor for a non-empty list (Data.List.NonEmpty). > > > >http://hackage.haskell.org/package/semigroups-0.12.2/docs/Data-List-NonEmpty.html > > > > Interesting? this is the page I had found: http://www.haskell.org/haskellwiki/Non-empty_list > > > So why do we need both :| and <| (or cons) ? > Look at the definitions and type signatures: (<|) :: a -> NonEmpty a -> NonEmpty a a <| ~(b :| bs) = a :| b : bs (:|) :: a -> [a] -> NonEmpty a data NonEmpty a = a :| [a] (I found the type-sig for (:|) using ghci ":t"). It is now evident that the constructor (:|) takes element/list to build |NonEmpty a|, while (<|) appends an |a| to a |NonEmpty a|. From dennis.raddle at gmail.com Fri Mar 28 09:10:51 2014 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Fri, 28 Mar 2014 02:10:51 -0700 Subject: [Haskell-beginners] random monad Message-ID: I'm writing a program which uses a lot of pseudorandom numbers, and for that reason it would be nice to put the StdGen in a state monad. like let's say I want to combine error handling and storing the StdGen state. import Control.Monad.Error import Control.Monad.State data RandState = RandState StdGen -- Er is a monad that combines error handling and pseudorandom state type Er a = ErrorT String (State RandState) a -- to access random numbers, I could define things like erRandomR :: Random r => (r,r) -> Er r erRandomR (lo, hi) = do RandState g <- get let (value, g') = randomR (lo, hi) g put $ RandState g' return value erRandoms :: Random r => Er [r] erRandoms = do RandState g <- get let (g1, g2) = split g let values = randoms g1 put $ RandState g2 return values erRandomRs :: Random r => (r,r) -> Er [r] erRandomRs (lo,hi) = do RandState g <- get let (g1, g2) = split g let values = randomRs (lo,hi) g1 put $ RandState g2 return values -- I could define new ways of using random values, like choosing a random element of a list erChooseList :: [a] -> Er a erChooseList xs = do let l = length xs when (l==0) (throwError "in randomChooseList, passed null list") idx <- erRandomR (0,l-1) return $ xs !! idx However, after I got done with that, I realized that I wanted to add additional state, maybe a ReaderT , stuff like that--different in different parts of the program. But I always want access to random numbers with the same functions: erRandomR, erRandoms, etc. So I thought class Monad m => RandMonad m where putGen :: StdGen -> m () getGen :: m StdGen Then I could make Er an instance of RandMonad, like this type Er a = ErrorT String (State RandState) a instance RandMonad Er where putGen g = put (RandState g) getGen = do RandState g <- get return g Clearly I don't know what I'm doing, because when I tried to run this much I got the error "Type synonym Er should have 1 argument, but has been given none." I tried a bunch of variations of this but got nowhere. Can someone explain how I should conceive of this? -------------- next part -------------- An HTML attachment was scrubbed... URL: From nishantgeek at gmail.com Fri Mar 28 09:45:43 2014 From: nishantgeek at gmail.com (Nishant) Date: Fri, 28 Mar 2014 15:15:43 +0530 Subject: [Haskell-beginners] algorithms books or tutorial in haskell Message-ID: Hi, Can someone provide me link to some pdf or online tutorial where I can find backtracking / dynamic programming kind of algorithms discussed in details. Regards. Nishant -------------- next part -------------- An HTML attachment was scrubbed... URL: From nda at informatik.uni-kiel.de Fri Mar 28 09:46:37 2014 From: nda at informatik.uni-kiel.de (Nikita Danilenko) Date: Fri, 28 Mar 2014 10:46:37 +0100 Subject: [Haskell-beginners] random monad In-Reply-To: References: Message-ID: <533544FD.50906@informatik.uni-kiel.de> An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: 0x76C229F0.asc Type: application/pgp-keys Size: 8170 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 901 bytes Desc: OpenPGP digital signature URL: From gesh at gesh.uni.cx Fri Mar 28 10:48:53 2014 From: gesh at gesh.uni.cx (Gesh) Date: Fri, 28 Mar 2014 13:48:53 +0300 Subject: [Haskell-beginners] typeclass In-Reply-To: References: Message-ID: <8c712f06-0cc3-4268-9cad-5ee1d4be6255@email.android.com> On March 28, 2014 4:35:11 AM GMT+03:00, Dennis Raddle wrote: >If I write a function like this: > >f (x1,y1) (x2,y2) = (x1++x2,y1++y2) > >My understanding of typeclasses is just developing, but I notice this >is a >bit like "lifting" (++) into a tuple. Maybe there is some existing >typeclass and a 2-tuple is already an instance of it? Like arrow? > >D > > >------------------------------------------------------------------------ > >_______________________________________________ >Beginners mailing list >Beginners at haskell.org >http://www.haskell.org/mailman/listinfo/beginners Indeed. The (->) instance of Arrow exposes all sorts of nice combinators, such as: (***) :: (a -> b) -> (c -> d) -> (a,c) -> (b,d) (&&&) :: (a -> b) -> (a -> c) -> a -> (b,c) (+++) :: (a -> b) -> (a' -> b') -> Either a a' -> Either b b' (|||) :: (a -> c) -> (b -> c) -> Either a b -> c From hjgtuyl at chello.nl Fri Mar 28 11:08:17 2014 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Fri, 28 Mar 2014 12:08:17 +0100 Subject: [Haskell-beginners] Array/Vector like DS in haskell In-Reply-To: References: Message-ID: On Fri, 28 Mar 2014 06:30:38 +0100, Nishant wrote: > Can someone elaborate on how to create a DS which acts like an array or > vector and has same time complexity ? An often advised package is vector, see: http://www.haskell.org/haskellwiki/Numeric_Haskell:_A_Vector_Tutorial Regards, Henk-Jan van Tuyl -- Folding at home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming -- From hjgtuyl at chello.nl Fri Mar 28 11:27:37 2014 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Fri, 28 Mar 2014 12:27:37 +0100 Subject: [Haskell-beginners] algorithms books or tutorial in haskell In-Reply-To: References: Message-ID: On Fri, 28 Mar 2014 10:45:43 +0100, Nishant wrote: > Can someone provide me link to some pdf or online tutorial where I can > find > backtracking / dynamic programming kind of algorithms discussed in > details. The page http://www.haskell.org/haskellwiki/Research_papers/Monads_and_arrows mentions several papers on backtracking, though some links are broken. A dynamic programming example: http://www.haskell.org/haskellwiki/Dynamic_programming_example Regards, Henk-Jan van Tuyl -- Folding at home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming -- From allbery.b at gmail.com Fri Mar 28 13:56:05 2014 From: allbery.b at gmail.com (Brandon Allbery) Date: Fri, 28 Mar 2014 09:56:05 -0400 Subject: [Haskell-beginners] What is operator :| ? In-Reply-To: <20140328064828.GA6987@x60s.casa> References: <20140328064828.GA6987@x60s.casa> Message-ID: On Fri, Mar 28, 2014 at 2:48 AM, Francesco Ariis wrote: > On Fri, Mar 28, 2014 at 12:54:03AM -0500, John M. Dlugosz wrote: > > More generally, is there some effective way to search for > > non-alphabetical Haskell things? Google just ignores the > > "punctuation". > > You can find :| on Hayoo [1], the other handy place where to > look for APIs stuff being Hoogle [2] (Hoogle is more focused on > 'standard' Haskell libraries, Hayoo searches in all Hackage, > both have their usefulness). > From there, if I need to search, say, a blog post, I will refer > to the name of the typeclass/module/data and feed it to a search > engine (so in this case "data NonEmpty etc. etc."). > Apparently Google ignores punctuation in most cases [3]. > http://symbolhound.com is useful. -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From ngnr63q02 at sneakemail.com Fri Mar 28 22:05:50 2014 From: ngnr63q02 at sneakemail.com (John M. Dlugosz) Date: Fri, 28 Mar 2014 17:05:50 -0500 Subject: [Haskell-beginners] What is operator :| ? In-Reply-To: <1395989329.2553.99909509.15479C7B@webmail.messagingengine.com> References: <1395989329.2553.99909509.15479C7B@webmail.messagingengine.com> Message-ID: On 3/28/2014 1:48 AM, Karl Voelker wrote: > On Thu, Mar 27, 2014, at 10:54 PM, John M. Dlugosz wrote: >> More generally, is there some effective way to search for >> non-alphabetical Haskell things? >> Google just ignores the "punctuation". > > For that, you can use Hayoo. > > http://holumbus.fh-wedel.de/hayoo/hayoo.html > > -Karl > Awesome! Thanks for pointing that out. From ngnr63q02 at sneakemail.com Fri Mar 28 23:00:27 2014 From: ngnr63q02 at sneakemail.com (John M. Dlugosz) Date: Fri, 28 Mar 2014 18:00:27 -0500 Subject: [Haskell-beginners] Help on first program Message-ID: Can someone explain what's wrong here? What is the code below _really_ saying, vs what I meant? I don't understand the error messages yet. == input == module Main ( main ) where solve n src dest tmp = do solve (n-1) src tmp -- line 6 solve 1 src dest tmp solve (n-1) tmp dest -- line 8 solve 1 src dest _ = putStrLn "move a disk from " ++ src ++ " to " ++ dest -- line 11 main = do putStrLn "Towers of Hanoi problem" solve 5 "A" "B" "C" == output == Prelude> :reload [1 of 1] Compiling Main ( towers1.hs, interpreted ) Failed, modules loaded: none. Prelude> towers1.hs:6:8: Couldn't match expected type `[a0]' with actual type `[Char] -> [Char]' In the return type of a call of `solve' Probable cause: `solve' is applied to too few arguments In a stmt of a 'do' block: solve (n - 1) src tmp In the expression: do { solve (n - 1) src tmp; solve 1 src dest tmp; solve (n - 1) tmp dest } towers1.hs:8:8: Couldn't match expected type `[Char]' with actual type `[Char] -> [Char]' In the return type of a call of `solve' Probable cause: `solve' is applied to too few arguments In a stmt of a 'do' block: solve (n - 1) tmp dest In the expression: do { solve (n - 1) src tmp; solve 1 src dest tmp; solve (n - 1) tmp dest } towers1.hs:11:5: Couldn't match expected type `[Char]' with actual type `IO ()' In the return type of a call of `putStrLn' In the first argument of `(++)', namely `putStrLn "move a disk from "' In the expression: putStrLn "move a disk from " ++ src ++ " to " ++ dest From ngnr63q02 at sneakemail.com Fri Mar 28 23:02:26 2014 From: ngnr63q02 at sneakemail.com (John M. Dlugosz) Date: Fri, 28 Mar 2014 18:02:26 -0500 Subject: [Haskell-beginners] Help on first program In-Reply-To: References: Message-ID: Nevermind... it really is too few arguments. On 3/28/2014 6:00 PM, John M. Dlugosz wrote: > Can someone explain what's wrong here? What is the code below _really_ saying, vs what I > meant? I don't understand the error messages yet. > > == input == > module Main ( > main > ) where > > solve n src dest tmp = > do solve (n-1) src tmp -- line 6 > solve 1 src dest tmp > solve (n-1) tmp dest -- line 8 > > solve 1 src dest _ = > putStrLn "move a disk from " ++ src ++ " to " ++ dest -- line 11 > > > main = do > putStrLn "Towers of Hanoi problem" > solve 5 "A" "B" "C" > > > == output == > Prelude> :reload > [1 of 1] Compiling Main ( towers1.hs, interpreted ) > Failed, modules loaded: none. > Prelude> > towers1.hs:6:8: > Couldn't match expected type `[a0]' > with actual type `[Char] -> [Char]' > In the return type of a call of `solve' > Probable cause: `solve' is applied to too few arguments > In a stmt of a 'do' block: solve (n - 1) src tmp > In the expression: > do { solve (n - 1) src tmp; > solve 1 src dest tmp; > solve (n - 1) tmp dest } > > towers1.hs:8:8: > Couldn't match expected type `[Char]' > with actual type `[Char] -> [Char]' > In the return type of a call of `solve' > Probable cause: `solve' is applied to too few arguments > In a stmt of a 'do' block: solve (n - 1) tmp dest > In the expression: > do { solve (n - 1) src tmp; > solve 1 src dest tmp; > solve (n - 1) tmp dest } > > towers1.hs:11:5: > Couldn't match expected type `[Char]' with actual type `IO ()' > In the return type of a call of `putStrLn' > In the first argument of `(++)', namely > `putStrLn "move a disk from "' > In the expression: > putStrLn "move a disk from " ++ src ++ " to " ++ dest > From ngnr63q02 at sneakemail.com Fri Mar 28 23:10:20 2014 From: ngnr63q02 at sneakemail.com (John M. Dlugosz) Date: Fri, 28 Mar 2014 18:10:20 -0500 Subject: [Haskell-beginners] Help on first program In-Reply-To: References: Message-ID: OK, I'm really stuck now. This gives "out of memory" and doesn't print anything other than the first line of output. == source code == module Main ( main ) where solve n src dest tmp = do solve (n-1) src tmp dest solve 1 src dest tmp solve (n-1) tmp dest src solve 1 src dest _ = putStrLn ("move a disk from " ++ src ++ " to " ++ dest) main = do putStrLn "Towers of Hanoi problem" solve 5 "A" "B" "C" == end == Each recursive call is either 1 or (n-1) so it should count down 5,4,3,2,1 and stop the recursion. What am I missing? From allbery.b at gmail.com Fri Mar 28 23:14:50 2014 From: allbery.b at gmail.com (Brandon Allbery) Date: Fri, 28 Mar 2014 19:14:50 -0400 Subject: [Haskell-beginners] Help on first program In-Reply-To: References: Message-ID: On Fri, Mar 28, 2014 at 7:10 PM, John M. Dlugosz wrote: > Each recursive call is either 1 or (n-1) so it should count down 5,4,3,2,1 > and stop the recursion. > What am I missing? It doesn't magically stop at 0; Integer (inferred type) is signed. Moreover, even if it were not signed, it would wrap around (or possibly throw an exception on some CPUs, but not on Intel). You need to include a check for 0 to stop the recursion. -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From ngnr63q02 at sneakemail.com Fri Mar 28 23:49:07 2014 From: ngnr63q02 at sneakemail.com (John M. Dlugosz) Date: Fri, 28 Mar 2014 18:49:07 -0500 Subject: [Haskell-beginners] Help on first program In-Reply-To: References: Message-ID: On 3/28/2014 6:14 PM, Brandon Allbery wrote: > On Fri, Mar 28, 2014 at 7:10 PM, John M. Dlugosz > wrote: > > Each recursive call is either 1 or (n-1) so it should count down 5,4,3,2,1 and stop > the recursion. > > What am I missing? > > > It doesn't magically stop at 0; Integer (inferred type) is signed. Moreover, even if it > were not signed, it would wrap around (or possibly throw an exception on some CPUs, but > not on Intel). You need to include a check for 0 to stop the recursion. > I don't get it. When n == 1 it should match the second form, and that is not recursive. Ah, they are matched in order! (Yes, it works if I reverse the clauses) Hmm, so it figures out the type from all of them? I worried about putting specialized ones first because there is far less information. From allbery.b at gmail.com Fri Mar 28 23:56:44 2014 From: allbery.b at gmail.com (Brandon Allbery) Date: Fri, 28 Mar 2014 19:56:44 -0400 Subject: [Haskell-beginners] Help on first program In-Reply-To: References: Message-ID: On Fri, Mar 28, 2014 at 7:49 PM, John M. Dlugosz wrote: > On 3/28/2014 6:14 PM, Brandon Allbery wrote: > >> On Fri, Mar 28, 2014 at 7:10 PM, John M. Dlugosz < >> ngnr63q02 at sneakemail.com >> > wrote: >> >> Each recursive call is either 1 or (n-1) so it should count down >> 5,4,3,2,1 and stop >> the recursion. >> >> What am I missing? >> >> It doesn't magically stop at 0; Integer (inferred type) is signed. >> Moreover, even if it >> were not signed, it would wrap around (or possibly throw an exception on >> some CPUs, but >> not on Intel). You need to include a check for 0 to stop the recursion. >> >> I don't get it. When n == 1 it should match the second form, and that > is not recursive. > > Ah, they are matched in order! > (Yes, it works if I reverse the clauses) Hmm, so it figures out the type from all of them? I worried about putting > specialized ones first because there is far less information. It uses all of them to get the type, yes. And the more specific pattern must come first; the first one always matches in this case because `n` doesn't give it any way not to match. If you had warnings enabled, the compiler should have warned you that the second form wouldn't be matched (although you may also need optimization turned on). The compiler doesn't see the different implementations as independent, and in fact doesn't see multiple implementations of the function at all at type resolution time; it's translated to a single function applying `case` to the parameters to determine which clause of the body to evaluate. -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From ngnr63q02 at sneakemail.com Sat Mar 29 04:13:19 2014 From: ngnr63q02 at sneakemail.com (John M. Dlugosz) Date: Fri, 28 Mar 2014 23:13:19 -0500 Subject: [Haskell-beginners] Help on first program In-Reply-To: References: Message-ID: On 3/28/2014 6:56 PM, Brandon Allbery wrote: > It uses all of them to get the type, yes. And the more specific pattern must come first; > the first one always matches in this case because `n` doesn't give it any way not to > match. If you had warnings enabled, the compiler should have warned you that the second > form wouldn't be matched (although you may also need optimization turned on). I was wondering about that. I'll look for warning flags. I was loading into GHCi rather than running the compiler from the command line. > > The compiler doesn't see the different implementations as independent, and in fact doesn't > see multiple implementations of the function at all at type resolution time; it's > translated to a single function applying `case` to the parameters to determine which > clause of the body to evaluate. Can they be spread out among different source files or be discontiguous within one file? From allbery.b at gmail.com Sat Mar 29 04:22:31 2014 From: allbery.b at gmail.com (Brandon Allbery) Date: Sat, 29 Mar 2014 00:22:31 -0400 Subject: [Haskell-beginners] Help on first program In-Reply-To: References: Message-ID: On Sat, Mar 29, 2014 at 12:13 AM, John M. Dlugosz wrote: > On 3/28/2014 6:56 PM, Brandon Allbery wrote: > >> The compiler doesn't see the different implementations as independent, >> and in fact doesn't >> > see multiple implementations of the function at all at type resolution >> time; it's >> translated to a single function applying `case` to the parameters to >> determine which >> clause of the body to evaluate. >> > > Can they be spread out among different source files or be discontiguous > within one file? Neither one; they must be together in the same file with nothing intervening, since they get rewritten into a single function. They also must all have the same number of parameters, even if one of them could take advantage of eta reduction (see http://www.haskell.org/haskellwiki/Eta_conversion), since the combination into a single function uses a common set of parameters. -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From ngnr63q02 at sneakemail.com Sat Mar 29 05:18:46 2014 From: ngnr63q02 at sneakemail.com (John M. Dlugosz) Date: Sat, 29 Mar 2014 00:18:46 -0500 Subject: [Haskell-beginners] Why is this not a "category"? Message-ID: on https://en.wikibooks.org/w/index.php?title=Haskell/Category_theory&stable=0#Hask.2C_the_Haskell_category the second exercise in the box (see illustration there) asks "(Harder.) If we add another morphism to the above example, it fails to be a category. Why? Hint: think about associativity of the composition operation." There are no answers-to-exercises. Can someone explain to me why adding another function with the same type causes the Haskell type system to no longer form the Hask category? (scratching head) From nrujac at gmail.com Sat Mar 29 05:47:01 2014 From: nrujac at gmail.com (Arjun Comar) Date: Sat, 29 Mar 2014 01:47:01 -0400 Subject: [Haskell-beginners] Why is this not a "category"? In-Reply-To: References: Message-ID: You're misreading the question. It's asking you to show that the category induced by the <= relation fails associativity if you add an extra morphism. On Mar 29, 2014 1:19 AM, "John M. Dlugosz" wrote: > on https://en.wikibooks.org/w/index.php?title=Haskell/ > Category_theory&stable=0#Hask.2C_the_Haskell_category > > the second exercise in the box (see illustration there) asks > "(Harder.) If we add another morphism to the above example, it fails to be > a category. Why? Hint: think about associativity of the composition > operation." > > There are no answers-to-exercises. Can someone explain to me why adding > another function with the same type causes the Haskell type system to no > longer form the Hask category? > > (scratching head) > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dennis.raddle at gmail.com Sat Mar 29 10:32:09 2014 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Sat, 29 Mar 2014 03:32:09 -0700 Subject: [Haskell-beginners] understanding MTL Message-ID: I had an interaction on #haskell today which left me utterly confused but desiring to understand what happened. I was talking about a program in which I was using stacks of monad transformers, inspiration taken from the paper "Monad Transformers: Step by Step". So for example I wanted to combine state and error handling in a Monadic type called "Er". data ErState = ErState StdGen newtype Er a = Er { runEr :: ErrorT String (State ErState) a } deriving(Monad, MonadError String, MonadState ErState) Note that ErState holds a random generator. I had the idea to make a typeclass of monadic types that hold random generators because I'll be using them in other types all over my application. Something like class Monad m => RandomMonad m where getGen :: m StdGen putGen :: StdGen -> m () Then I can write functions like this: myRandoms :: (Random a, RandomMonad m) => m [a] myRandoms = do g <- getGen let (g1, g2) = split g values = randoms g1 putGen g2 return values So then mm_freak on #haskell noticed that I had written a function with a signature like process :: Int -> Er Int He said, no no no functions should be agnostic with regard to data structure. It should look something like process :: (RandomMonad m, MonadError m, MonadState m) => Int -> m Int He then said I don't want to put StateT and ErrorT in the same newtype declaration, so it would be something like newtype Er m a = Er { runEr :: StateT ErState m a } On this point I'm confused. I don't know how to get from a line like the above to eventually making a type that combines error handling and state. Furthermore I need to define instances for things like MonadError. He got me started with the line instance MonadError e m => MonadError e (Er m) where ... define throwError and catchError which I have no idea how to do ... So where we left it, I was confused and didn't understand anything. Rather than just getting the answers, I want to try to understand this, but I feel like I must need more background. This must be the kind of code that is in the monad transformer library. Is there a guide to understanding that somewhere? D -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Sat Mar 29 19:29:01 2014 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Sun, 30 Mar 2014 02:29:01 +0700 Subject: [Haskell-beginners] Why is this not a "category"? In-Reply-To: References: Message-ID: On Sat, Mar 29, 2014 at 12:18 PM, John M. Dlugosz wrote: > "(Harder.) If we add another morphism to the above example, it fails to be > a category. Why? Hint: think about associativity of the composition > operation." One has to be careful with crowd-sourced wikipedia-like learning material. They aren't always helpful, although 80% of the time they are. In this case, the 2 exercises probably belong right after the section on "Category Laws" but _before_ "Hask, the Haskell category." That way, there's less confusion about what the exercises refer to and what they do NOT refer to. They certainly don't refer to Hask. That said, the exercises presume acquaintance with partial orders / posets so there's some web-trawling to be done if the requirement is unmet. And I'll also argue that the exercises aren't helpful. They may have their place in some musty math textbook. But for a general audience, it's like having some obscure concept (category) explained in terms of another obscure concept (partial order), with no-one getting any wiser. p.s. if you are still stuck email me off-list for the answer. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From ngnr63q02 at sneakemail.com Sat Mar 29 23:42:08 2014 From: ngnr63q02 at sneakemail.com (John M. Dlugosz) Date: Sat, 29 Mar 2014 18:42:08 -0500 Subject: [Haskell-beginners] Help on first program In-Reply-To: References: Message-ID: On 3/28/2014 11:22 PM, Brandon Allbery wrote: > Can they be spread out among different source files or be discontiguous within one file? > > Neither one; they must be together in the same file with nothing intervening, since they > get rewritten into a single function. They also must all have the same number of > parameters, even if one of them could take advantage of eta reduction Many thanks. From karl at karlv.net Sun Mar 30 04:19:14 2014 From: karl at karlv.net (Karl Voelker) Date: Sat, 29 Mar 2014 21:19:14 -0700 Subject: [Haskell-beginners] understanding MTL In-Reply-To: References: Message-ID: <1396153154.14981.100522269.384FF1AC@webmail.messagingengine.com> On Sat, Mar 29, 2014, at 03:32 AM, Dennis Raddle wrote: He then said I don't want to put StateT and ErrorT in the same newtype declaration, so it would be something like newtype Er m a = Er { runEr :: StateT ErState m a } On this point I'm confused. I don't know how to get from a line like the above to eventually making a type that combines error handling and state. Furthermore I need to define instances for things like MonadError. I don't think there was really anything wrong with your prior approach. It seems like the advice you got was to make the Er type more generic, which may or may not be appropriate in the context of your application. At this point, Er is now a monad transformer. It's not really a monad until the "m" type parameter is instantiated. For example: type ErActuallyAMonad a = Er Error a Notice that the value inside the newtype will then be a "StateT ErState Error a", which is almost the same as the "ErrorT (State ErState) a" you had originally. He got me started with the line instance MonadError e m => MonadError e (Er m) where ... define throwError and catchError which I have no idea how to do ... An instance declaration like this is saying that if you have a MonadError monad m, and you transform it with the transformer Er, then the resulting monad will also be a MonadError monad. These instance declarations are pretty common in the MTL. -Karl -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin.drautzburg at web.de Mon Mar 31 16:07:20 2014 From: martin.drautzburg at web.de (martin) Date: Mon, 31 Mar 2014 18:07:20 +0200 Subject: [Haskell-beginners] Mapping inside State Message-ID: <533992B8.3090206@web.de> Hello all, I found myselft writing this ugly piece of code silenceAll :: TI -> State (M.Map CH StringState,[DtzEvent]) TI silenceAll t = silence t 0 >> silence t 1 >> silence t 2 >> silence t 3 >> silence t 4 >> silence t 5 >> silence t 6 >> return t because I couldn't figure out how to map (silence t) over [0..6]. What is the standard way of doing this? From ozgurakgun at gmail.com Mon Mar 31 16:25:51 2014 From: ozgurakgun at gmail.com (Ozgur Akgun) Date: Mon, 31 Mar 2014 17:25:51 +0100 Subject: [Haskell-beginners] Mapping inside State In-Reply-To: <533992B8.3090206@web.de> References: <533992B8.3090206@web.de> Message-ID: Hi Martin, mapM_ is what you are looking for. Please ask again if you don't manage to make it work for you. Cheers, Ozgur. -------------- next part -------------- An HTML attachment was scrubbed... URL: From chaddai.fouche at gmail.com Mon Mar 31 20:42:06 2014 From: chaddai.fouche at gmail.com (=?UTF-8?B?Q2hhZGRhw68gRm91Y2jDqQ==?=) Date: Mon, 31 Mar 2014 22:42:06 +0200 Subject: [Haskell-beginners] Mapping inside State In-Reply-To: <533992B8.3090206@web.de> References: <533992B8.3090206@web.de> Message-ID: Le 31 mars 2014 18:07, "martin" a ?crit : > > Hello all, > > I found myselft writing this ugly piece of code > > silenceAll :: TI -> State (M.Map CH StringState,[DtzEvent]) TI > silenceAll t = Cut > > because I couldn't figure out how to map (silence t) over [0..6]. What is the standard way of doing this As said, mapM_ is the standard way to do that . How could you have found this for yourself ? The recommended way would be to use hoogle to search for the type signature you wish : (Monad m) => (a -> m b) -> [a] -> m () mapM_ would be among the first results. -- Jeda? -------------- next part -------------- An HTML attachment was scrubbed... URL: