From andrew.bernard at gmail.com Sun Nov 1 02:24:07 2015 From: andrew.bernard at gmail.com (Andrew Bernard) Date: Sun, 1 Nov 2015 13:24:07 +1100 Subject: [Haskell-beginners] randmomR produces only even values In-Reply-To: <5633BA4B.7030101@web.de> References: <5633BA4B.7030101@web.de> Message-ID: <9B390FE9-586C-45AF-92A5-85A090E3768C@gmail.com> According to the package documentation for System.Random: This implementation uses the Portable Combined Generator of L'Ecuyer [System.Random] for 32-bit computers, transliterated by Lennart Augustsson. The paper in question is given as: Pierre L'Ecuyer, /Efficient and portable combined random number generators/, Comm ACM, 31(6), Jun 1988, pp742-749 Does anybody have a copy of this paper? The use of an incrementing list of integers to seed each generation is definitely unusual, as Lyndon has pointed out, and is likely to be the root of the observed behaviour. Having the paper in question would probably clarify this. Andrew From hjgtuyl at chello.nl Sun Nov 1 15:12:46 2015 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Sun, 01 Nov 2015 16:12:46 +0100 Subject: [Haskell-beginners] randmomR produces only even values In-Reply-To: <9B390FE9-586C-45AF-92A5-85A090E3768C@gmail.com> References: <5633BA4B.7030101@web.de> <9B390FE9-586C-45AF-92A5-85A090E3768C@gmail.com> Message-ID: On Sun, 01 Nov 2015 03:24:07 +0100, Andrew Bernard wrote: > According to the package documentation for System.Random: > > This implementation uses the Portable Combined Generator of L'Ecuyer > [System.Random] for 32-bit computers, transliterated by Lennart > Augustsson. > > The paper in question is given as: > > Pierre L'Ecuyer, /Efficient and portable combined random number > generators/, Comm ACM, 31(6), Jun 1988, pp742-749 > > Does anybody have a copy of this paper? The first result of a search with startpage was: http://www.iro.umontreal.ca/~lecuyer/myftp/papers/cacm88.pdf 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 abhishekkmr18 at gmail.com Sun Nov 1 17:50:15 2015 From: abhishekkmr18 at gmail.com (Abhishek Kumar) Date: Sun, 1 Nov 2015 23:20:15 +0530 Subject: [Haskell-beginners] Getting Started Message-ID: Hello Everyone I am new to haskell (learning right now). I want to contribute to data structure and algorithm libraries in haskell.Please guide me with appropriate links and how to start with.I have previous implementation experience in other languages. Thanks Abhishek Kumar -------------- next part -------------- An HTML attachment was scrubbed... URL: From chaddai.fouche at gmail.com Sun Nov 1 21:42:12 2015 From: chaddai.fouche at gmail.com (=?UTF-8?B?Q2hhZGRhw68gRm91Y2jDqQ==?=) Date: Sun, 01 Nov 2015 21:42:12 +0000 Subject: [Haskell-beginners] randmomR produces only even values In-Reply-To: References: <5633BA4B.7030101@web.de> <9B390FE9-586C-45AF-92A5-85A090E3768C@gmail.com> Message-ID: I really don't think this is much of a flaw. It may need to be reinforced that this package (and most random libraries) doesn't provide _any_ guarantee if you use it like that (restrain the first output with randomR of lots of random generators initialized by very particular seeds sequence). The guarantee the paper will be talking about will be for a sequence of random numbers generated by one generator and this behave normally as shown by : > (minimum &&& maximum) . map (length . filter even . take 1000 . randomRs (1,10) . mkStdGen) $ [1..1000] (432,553) In other words, if there's any problem it is only one of documentation (just a warning in the haddock ought to be sufficient). -- Jeda? -------------- next part -------------- An HTML attachment was scrubbed... URL: From magnus at therning.org Mon Nov 2 07:39:18 2015 From: magnus at therning.org (Magnus Therning) Date: Mon, 2 Nov 2015 08:39:18 +0100 Subject: [Haskell-beginners] Getting Started In-Reply-To: References: Message-ID: <20151102073918.GA10863@sobel.cipherstone.com> On Sun, Nov 01, 2015 at 11:20:15PM +0530, Abhishek Kumar wrote: > Hello Everyone > > I am new to haskell (learning right now). I want to contribute to data > structure and algorithm libraries in haskell.Please guide me with > appropriate links and how to start with.I have previous implementation > experience in other languages. Once you've gotten into the language I suggest you explore [Hackage][1] and look for something that tickles your fancy when it comes to contributing. /M [1]: http://hackage.haskell.org/ -- Magnus Therning OpenPGP: 0xAB4DFBA4 email: magnus at therning.org jabber: magnus at therning.org twitter: magthe http://therning.org/magnus Increasingly, people seem to misinterpret complexity as sophistication, which is baffling--the incomprehensible should cause suspicion rather than admiration. -- Niklaus Wirth -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 163 bytes Desc: not available URL: From abhishekkmr18 at gmail.com Mon Nov 2 08:03:18 2015 From: abhishekkmr18 at gmail.com (Abhishek Kumar) Date: Mon, 2 Nov 2015 13:33:18 +0530 Subject: [Haskell-beginners] Getting Started In-Reply-To: <20151102073918.GA10863@sobel.cipherstone.com> References: <20151102073918.GA10863@sobel.cipherstone.com> Message-ID: Thanks Magnus Therning I came across following libraries http://hackage.haskell.org/package/graphs graphs and http://hackage.haskell.org/package/bytestring-trie and few others. I am not sure whether these libraries are under active development and I can find some beginner level bugs there to start with.Can someone please suggest me some libraries having open beginner issues. Thanks Abhishek Kumar On Mon, Nov 2, 2015 at 1:09 PM, Magnus Therning wrote: > On Sun, Nov 01, 2015 at 11:20:15PM +0530, Abhishek Kumar wrote: > > Hello Everyone > > > > I am new to haskell (learning right now). I want to contribute to data > > structure and algorithm libraries in haskell.Please guide me with > > appropriate links and how to start with.I have previous implementation > > experience in other languages. > > Once you've gotten into the language I suggest you explore [Hackage][1] > and look for something that tickles your fancy when it comes to > contributing. > > /M > > [1]: http://hackage.haskell.org/ > > -- > Magnus Therning OpenPGP: 0xAB4DFBA4 > email: magnus at therning.org jabber: magnus at therning.org > twitter: magthe http://therning.org/magnus > > Increasingly, people seem to misinterpret complexity as sophistication, > which is baffling--the incomprehensible should cause suspicion rather than > admiration. > -- Niklaus Wirth > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From magnus at therning.org Mon Nov 2 08:11:19 2015 From: magnus at therning.org (Magnus Therning) Date: Mon, 2 Nov 2015 09:11:19 +0100 Subject: [Haskell-beginners] Getting Started In-Reply-To: References: <20151102073918.GA10863@sobel.cipherstone.com> Message-ID: <20151102081119.GC10863@sobel.cipherstone.com> On Mon, Nov 02, 2015 at 01:33:18PM +0530, Abhishek Kumar wrote: > Thanks Magnus Therning > > I came across following libraries > http://hackage.haskell.org/package/graphs graphs and > http://hackage.haskell.org/package/bytestring-trie and few others. Oh, there are so many more on there :) > I am not sure whether these libraries are under active development and > I can find some beginner level bugs there to start with.Can someone > please suggest me some libraries having open beginner issues. That sort of thing you're only likely to find on the individual libraries' home pages. So you have to start following links from Hackage to their homes. I suspect only larger projects might maintain a list of beginner-friendly bugs. I do believe the compiler itself, ghc, tries to mark some bugs as easy-to-fix. /M -- Magnus Therning OpenPGP: 0xAB4DFBA4 email: magnus at therning.org jabber: magnus at therning.org twitter: magthe http://therning.org/magnus The cheapest, fastest and most reliable components of a computer system are those that aren't there. -- Gordon Bell -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 163 bytes Desc: not available URL: From chaddai.fouche at gmail.com Tue Nov 3 06:56:59 2015 From: chaddai.fouche at gmail.com (=?UTF-8?B?Q2hhZGRhw68gRm91Y2jDqQ==?=) Date: Tue, 03 Nov 2015 06:56:59 +0000 Subject: [Haskell-beginners] let , equations, and monads In-Reply-To: References: Message-ID: Hello, Le mer. 28 oct. 2015 ? 15:59, PATRICK BROWNE a ?crit : > {- From Learn Haskell Fast and Hard : 4.3.1. Maybe is a monad > http://yannesposito.com/Scratch/en/blog/Haskell-the-Hard-Way/#maybe-monad > > Concerning the code below I have the following questions: > 1) Are eligibleLet and eligibleEquational operationally equivalent (i.e. > perform the same operations) and/or semantically equivalent(i.e. > Church-Rosser)? > A priori, they're only semantically equivalent since in eligibleEquational intermediary computation are repeated whereas in eligibleLet they're only effectued once. > 2) Apart from the return type of Maybe instead of Bool how does > eligibleMonad differ from eligibleLet? > eligibleMonad is nice and readable while eligibleLet is a tiresome mess to write and maintain... Basically in eligibleMonad the logic that checks whether an operation is possible is rolled into the monadic operations themselves whereas in eligibleLet you have to check every operation validity yourself (so you can forget one or do it incorrectly). Note that with more familiarity with monads, you would probably rewrite eligibleMonad to avoid naming the intermediary account (and thus avoid any confusion between versions) : eligibleMonad account = depositM 100 account >>= withdrawM 200 >>= depositM 100 >>= withdrawM 300 >>= depositM 1000 >> Just True This would make it very easy to add or remove operations. -- Jeda? -------------- next part -------------- An HTML attachment was scrubbed... URL: From alexandre+haskell at delanoe.org Tue Nov 3 10:12:31 2015 From: alexandre+haskell at delanoe.org (Alexandre =?iso-8859-1?Q?Delano=EB?=) Date: Tue, 3 Nov 2015 11:12:31 +0100 Subject: [Haskell-beginners] Partition a list recursively Message-ID: <20151103101231.GA9610@delanoe.org> Hello, I am looking for such function: function :: Ord a => [a] -> [a] -> [[a]] function [1,3,6] [0..6] == [[0,1],[2,3],[4,5,6]] Question: does it exist already ? If no, continue: Let: partIt :: Ord a => a -> [a] -> [[a]] partIt m xs = [takeWhile (<= m) xs, dropWhile (<= m) xs] example: partIt 1 [0..5] == [[0,1],[2,3,4,5]] Question: How to define recursively partIt 1) with a list as parameter ? 2) recursively on the second part of the list ? Thanks for help, -- Alexandre Delano? From fa-ml at ariis.it Tue Nov 3 11:46:29 2015 From: fa-ml at ariis.it (Francesco Ariis) Date: Tue, 3 Nov 2015 12:46:29 +0100 Subject: [Haskell-beginners] Partition a list recursively In-Reply-To: <20151103101231.GA9610@delanoe.org> References: <20151103101231.GA9610@delanoe.org> Message-ID: <20151103114629.GA9193@casa.casa> On Tue, Nov 03, 2015 at 11:12:31AM +0100, Alexandre Delano? wrote: > Hello, > I am looking for such function: > > function :: Ord a => [a] -> [a] -> [[a]] > function [1,3,6] [0..6] == [[0,1],[2,3],[4,5,6]] > > Question: does it exist already ? ``Data.List.Split`` (from package ``split``) may have what you are looking for. > > Let: > > partIt :: Ord a => a -> [a] -> [[a]] > partIt m xs = [takeWhile (<= m) xs, dropWhile (<= m) xs] > example: > partIt 1 [0..5] == [[0,1],[2,3,4,5]] > > Question: How to define recursively partIt > 1) with a list as parameter ? > 2) recursively on the second part of the list ? With pattern matching: partIt :: Ord a => a -> [a] -> [[a]] partIt [] xs = xs partIt (m:ms) xs = let (a, b) = span (<= m) xs in (a : partIt ms b) ?> partIt [1,3,6] [0..6] [[0,1],[2,3],[4,5,6],[]] -- expected: splits on 6 too Learn You a Haskell has nice section on pattern matching. Did this answer the question? From patrick.browne at dit.ie Tue Nov 3 12:24:46 2015 From: patrick.browne at dit.ie (PATRICK BROWNE) Date: Tue, 3 Nov 2015 12:24:46 +0000 Subject: [Haskell-beginners] let , equations, and monads In-Reply-To: References: Message-ID: Chadda?, Thank you very much for your response to my question. It confirms my intuition, but I was not sure. Is it true in general that let expressions (e.g. eligibleLet) are always semantically equivalent to their equational counterparts (e.g. eligibleEquational)? Would it be fair to say that "let" is syntactic sugar for an equational equivalent? Or is there more to it? With respect to the ordering of the operations is generally true that a monadic version is semantically equivalent to a set of "let expressions" in a nested if-then-else? Thanks, Pat On 3 November 2015 at 06:56, Chadda? Fouch? wrote: > Hello, > > Le mer. 28 oct. 2015 ? 15:59, PATRICK BROWNE a > ?crit : > >> {- From Learn Haskell Fast and Hard : 4.3.1. Maybe is a monad >> >> http://yannesposito.com/Scratch/en/blog/Haskell-the-Hard-Way/#maybe-monad >> >> Concerning the code below I have the following questions: >> 1) Are eligibleLet and eligibleEquational operationally equivalent (i.e. >> perform the same operations) and/or semantically equivalent(i.e. >> Church-Rosser)? >> > > A priori, they're only semantically equivalent since in eligibleEquational > intermediary computation are repeated whereas in eligibleLet they're only > effectued once. > > >> 2) Apart from the return type of Maybe instead of Bool how does >> eligibleMonad differ from eligibleLet? >> > > eligibleMonad is nice and readable while eligibleLet is a tiresome mess to > write and maintain... > Basically in eligibleMonad the logic that checks whether an operation is > possible is rolled into the monadic operations themselves whereas in > eligibleLet you have to check every operation validity yourself (so you can > forget one or do it incorrectly). > > Note that with more familiarity with monads, you would probably rewrite > eligibleMonad to avoid naming the intermediary account (and thus avoid any > confusion between versions) : > > eligibleMonad account = depositM 100 account > >>= withdrawM 200 > >>= depositM 100 > >>= withdrawM 300 > >>= depositM 1000 > >> Just True > > This would make it very easy to add or remove operations. > > > -- > Jeda? > -- This email originated from DIT. If you received this email in error, please delete it from your system. Please note that if you are not the named addressee, disclosing, copying, distributing or taking any action based on the contents of this email or attachments is prohibited. www.dit.ie Is ? ITB?C a th?inig an r?omhphost seo. M? fuair t? an r?omhphost seo tr? earr?id, scrios de do ch?ras ? le do thoil. Tabhair ar aird, mura t? an seola? ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon ch?ipe?il, aon d?ileadh n? ar aon ghn?omh a dh?anfar bunaithe ar an ?bhar at? sa r?omhphost n? sna hiat?in seo. www.dit.ie T? ITB?C ag aistri? go Gr?inseach Ghorm?in ? DIT is on the move to Grangegorman -------------- next part -------------- An HTML attachment was scrubbed... URL: From alexandre+haskell at delanoe.org Tue Nov 3 13:29:07 2015 From: alexandre+haskell at delanoe.org (Alexandre =?iso-8859-1?Q?Delano=EB?=) Date: Tue, 3 Nov 2015 14:29:07 +0100 Subject: [Haskell-beginners] Partition a list recursively In-Reply-To: <20151103114629.GA9193@casa.casa> References: <20151103101231.GA9610@delanoe.org> <20151103114629.GA9193@casa.casa> Message-ID: <20151103132907.GA20041@delanoe.org> 2015/11/03 12:46, Francesco Ariis: > On Tue, Nov 03, 2015 at 11:12:31AM +0100, Alexandre Delano? wrote: > > Hello, > > I am looking for such function: > > > > function :: Ord a => [a] -> [a] -> [[a]] > > function [1,3,6] [0..6] == [[0,1],[2,3],[4,5,6]] > > > > Question: does it exist already ? > > ``Data.List.Split`` (from package ``split``) may have what you are > looking for. Thanks. I had a look on it but I did not find what I need (maybe I am wrong). In fact, "span" was exactly the tool indeed (see below). > > > > Let: > > > > partIt :: Ord a => a -> [a] -> [[a]] > > partIt m xs = [takeWhile (<= m) xs, dropWhile (<= m) xs] > > example: > > partIt 1 [0..5] == [[0,1],[2,3,4,5]] > > > > Question: How to define recursively partIt > > 1) with a list as parameter ? > > 2) recursively on the second part of the list ? > > With pattern matching: > > partIt :: Ord a => a -> [a] -> [[a]] > partIt [] xs = xs > partIt (m:ms) xs = let (a, b) = span (<= m) xs in (a : partIt ms b) Thanks! Yes, exactly. With some minor corrections: partIt :: Ord a => [a] -> [a] -> [[a]] partIt [] xs = [xs] partIt (m:ms) xs = let (a, b) = span (<= m) xs in (a : partIt ms b) > ?> partIt [1,3,6] [0..6] > [[0,1],[2,3],[4,5,6],[]] -- expected: splits on 6 too ok > > Learn You a Haskell has nice section on pattern matching. > Did this answer the question? Yes, now it is time to practice and I discover (each time) how pattern matching is powerful. Thanks again, -- Alexandre Delano? From chaddai.fouche at gmail.com Tue Nov 3 15:59:25 2015 From: chaddai.fouche at gmail.com (=?UTF-8?B?Q2hhZGRhw68gRm91Y2jDqQ==?=) Date: Tue, 03 Nov 2015 15:59:25 +0000 Subject: [Haskell-beginners] let , equations, and monads In-Reply-To: References: Message-ID: Le mar. 3 nov. 2015 ? 13:24, PATRICK BROWNE a ?crit : > Chadda?, > Thank you very much for your response to my question. It confirms my > intuition, but I was not sure. > > Is it true in general that let expressions (e.g. eligibleLet) are always > semantically equivalent to their equational counterparts (e.g. > eligibleEquational)? > Yes, in Haskell that is true because it is pure/referentially transparent (absent case of misuse of the "escape hatch"es like unsafePerformIO). That is one of the big advantage : that you're always able to reason equationally. (note that this remains true with monads, they're not impure, they're just a notation that can describe impure computations) > Would it be fair to say that "let" is syntactic sugar for an equational > equivalent? Or is there more to it? > "let x = stuff in expr" is syntactic sugar for "(\x -> expr) stuff" basically. Though there's a few syntactical conveniences that complicate the translation. > With respect to the ordering of the operations is generally true that a > monadic version is semantically equivalent to a set of "let expressions" > in a nested if-then-else? > Well with the Maybe monad like here yes, though that's more of a nested case-of. With IO this is more complicated, especially if you use forkIO (concurrency). > > Thanks, > You're welcome ! -- Chadda? -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Tue Nov 3 16:50:21 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Tue, 3 Nov 2015 22:20:21 +0530 Subject: [Haskell-beginners] Getting Started In-Reply-To: <20151102081119.GC10863@sobel.cipherstone.com> References: <20151102073918.GA10863@sobel.cipherstone.com> <20151102081119.GC10863@sobel.cipherstone.com> Message-ID: I remember hearing that Cabal has a lot of labeled easy-to-fix bugs: https://github.com/haskell/cabal/issues?q=is%3Aopen+is%3Aissue+label%3Aeasy On 2 November 2015 at 13:41, Magnus Therning wrote: > On Mon, Nov 02, 2015 at 01:33:18PM +0530, Abhishek Kumar wrote: > > Thanks Magnus Therning > > > > I came across following libraries > > http://hackage.haskell.org/package/graphs graphs and > > http://hackage.haskell.org/package/bytestring-trie and few others. > > Oh, there are so many more on there :) > > > I am not sure whether these libraries are under active development and > > I can find some beginner level bugs there to start with.Can someone > > please suggest me some libraries having open beginner issues. > > That sort of thing you're only likely to find on the individual > libraries' home pages. So you have to start following links from > Hackage to their homes. I suspect only larger projects might maintain a > list of beginner-friendly bugs. I do believe the compiler itself, ghc, > tries to mark some bugs as easy-to-fix. > > /M > > -- > Magnus Therning OpenPGP: 0xAB4DFBA4 > email: magnus at therning.org jabber: magnus at therning.org > twitter: magthe http://therning.org/magnus > > The cheapest, fastest and most reliable components of a computer system > are those that aren't there. > -- Gordon Bell > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjakway at nyu.edu Tue Nov 3 22:24:05 2015 From: tjakway at nyu.edu (Thomas Jakway) Date: Tue, 3 Nov 2015 17:24:05 -0500 Subject: [Haskell-beginners] List of a Data Type Message-ID: <56393405.5010909@nyu.edu> I've made a new datatype data Visibility a = Hidden a | Shown a I want to create a type that's a list of hidden and visible integers. So something like this: type possiblyVisibleInts = [Visibility Int] The idea is that some of the ints will be hidden and some will be shown. But it doesn't work. Why not? This seemed even odder to me after poking around in ghci: :t [Just 5, Nothing] gives [Just 5, Nothing] :: Num a => [Maybe a] So clearly it's possible to have a list of a type that has 2 constructors--you're not restricted to having a list that only contains Just, for example. ghci is also OK with e.g. :t [Hidden 5, Shown 6] [Hidden 5, Shown 6] :: Num a => [Visibility a] From ahammel87 at gmail.com Tue Nov 3 22:34:19 2015 From: ahammel87 at gmail.com (Alex Hammel) Date: Tue, 03 Nov 2015 22:34:19 +0000 Subject: [Haskell-beginners] List of a Data Type In-Reply-To: <56393405.5010909@nyu.edu> References: <56393405.5010909@nyu.edu> Message-ID: Works for me: Prelude> data Vis a = Hidden a | Shown a Prelude> :t [Hidden "foo", Shown "bar"] [Hidden "foo", Shown "bar"] :: [Vis [Char]] Prelude> type VisListInt = [Vis Int] Prelude> let foo = (id :: VisListInt -> VisListInt) Prelude> :t foo foo :: VisListInt -> VisListInt Prelude> :t foo [Hidden 2] foo [Hidden 2] :: VisListInt What error message are you seeing? Cheers, Alex On Tue, 3 Nov 2015 at 14:24 Thomas Jakway wrote: > I've made a new datatype > > data Visibility a = Hidden a | Shown a > > I want to create a type that's a list of hidden and visible integers. > So something like this: > > type possiblyVisibleInts = [Visibility Int] > > The idea is that some of the ints will be hidden and some will be shown. > > But it doesn't work. Why not? > This seemed even odder to me after poking around in ghci: > > :t [Just 5, Nothing] > gives > [Just 5, Nothing] :: Num a => [Maybe a] > > So clearly it's possible to have a list of a type that has 2 > constructors--you're not restricted to having a list that only contains > Just, for example. > > ghci is also OK with e.g. > > :t [Hidden 5, Shown 6] > [Hidden 5, Shown 6] :: Num a => [Visibility a] > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ozgurakgun at gmail.com Tue Nov 3 22:45:18 2015 From: ozgurakgun at gmail.com (Ozgur Akgun) Date: Tue, 3 Nov 2015 22:45:18 +0000 Subject: [Haskell-beginners] List of a Data Type In-Reply-To: <56393405.5010909@nyu.edu> References: <56393405.5010909@nyu.edu> Message-ID: On 3 November 2015 at 22:24, Thomas Jakway wrote: > type possiblyVisibleInts = [Visibility Int] > The case of the first letter is important: for type names, the first letter has to be capital. Ozgur -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjakway at nyu.edu Tue Nov 3 22:59:29 2015 From: tjakway at nyu.edu (Thomas Jakway) Date: Tue, 3 Nov 2015 17:59:29 -0500 Subject: [Haskell-beginners] List of a Data Type In-Reply-To: References: <56393405.5010909@nyu.edu> Message-ID: <56393C51.9040104@nyu.edu> Woops, thanks a ton! On 11/3/15 5:45 PM, Ozgur Akgun wrote: > > On 3 November 2015 at 22:24, Thomas Jakway > wrote: > > type possiblyVisibleInts = [Visibility Int] > > > The case of the first letter is important: for type names, the first > letter has to be capital. > > Ozgur > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From teztingit at gmail.com Wed Nov 4 07:29:24 2015 From: teztingit at gmail.com (goforgit .) Date: Wed, 4 Nov 2015 08:29:24 +0100 Subject: [Haskell-beginners] Add parenthesis to Sin/Cos expressions Message-ID: Hello! I've written a function that is supposed to add parenthesis to sin/cos expressions. For example - Sin5+3 -> Sin(5) + 3 - SinCos(5+3) -> Sin(Cos(5+3)) - SinCos5 * 3 -> Sin(Cos(5)) * 3 The problem is that it converts the following expression *SinSin(5+1+2)* into *Sin(Sin(5)+1+2)* Could someone point me to the direction of a solution to this? Thanks in advance! convert :: String -> String convert s = convert' s 0 convert' :: String -> Int -> String convert' [] n = replicate n ')' convert' (a:as) n | ((a == 'n' || a == 's') && ((take 1 as) /= "(")) = a : "(" ++ (convert' as (n+1)) | ((a == '+' || a == '*') && (n > 0)) = (replicate n ')') ++ [a] ++ (convert' as 0) | otherwise = a : (convert' as n) -------------- next part -------------- An HTML attachment was scrubbed... URL: From imantc at gmail.com Wed Nov 4 09:21:18 2015 From: imantc at gmail.com (Imants Cekusins) Date: Wed, 4 Nov 2015 10:21:18 +0100 Subject: [Haskell-beginners] Add parenthesis to Sin/Cos expressions In-Reply-To: References: Message-ID: > a function that is supposed to add parenthesis to sin/cos expressions. a) Sin 5 + 3 -> Sin(5) + 3 b) Sin Cos (5+3) -> Sin (Cos(5+3)) c) Sin Cos 5 * 3 -> Sin(Cos(5)) * 3 are you looking for textual representation or actual Haskell code which runs? if actual code, these examples may be re-written like this: a) sin 5 + 3 b) sin $ cos $ 5 + 3 c) sin (cos 5) * 3 From dominic at steinitz.org Wed Nov 4 09:58:15 2015 From: dominic at steinitz.org (Dominic Steinitz) Date: Wed, 4 Nov 2015 09:58:15 +0000 (UTC) Subject: [Haskell-beginners] randmomR produces only even values Message-ID: > http://article.gmane.org/gmane.comp.lang.haskell.beginners/15925 I do think this is a flaw and catches many people out despite apparently being well documented. And it's something one probably wants e.g. to run multiple Markov Chain Monte Carlo simulations in parallel. Some further information here: https://github.com/haskell/random/issues/30#issuecomment-153647055 Dominic From sumit.sahrawat.apm13 at iitbhu.ac.in Thu Nov 5 17:16:43 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Thu, 5 Nov 2015 22:46:43 +0530 Subject: [Haskell-beginners] Add parenthesis to Sin/Cos expressions In-Reply-To: References: Message-ID: The spirit of declarative programming lies in the fact that you try to just tell the compiler what something means. Instead of thinking about keeping track of the numbers of parentheses, and then applying them afterwards, I would suggest you create a function to do the same job: bracketed :: String -> String bracketed s = "(" ++ s ++ ")" This would allow you to remove the numeric argument, and also write cleaner code. The second thing that you can improve is the pattern matching. You can use isPrefixOf to check functions, or use a take inside a case statement to get cleaner handling of different cases. case take 3 str of "sin" -> ... "cos" -> ... _ -> ... This would also let you debug your code more easily, just as you require. On 4 November 2015 at 14:51, Imants Cekusins wrote: > > a function that is supposed to add parenthesis to sin/cos expressions. > a) Sin 5 + 3 -> Sin(5) + 3 > b) Sin Cos (5+3) -> Sin (Cos(5+3)) > c) Sin Cos 5 * 3 -> Sin(Cos(5)) * 3 > > are you looking for textual representation or actual Haskell code which > runs? > if actual code, these examples may be re-written like this: > a) sin 5 + 3 > b) sin $ cos $ 5 + 3 > c) sin (cos 5) * 3 > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From dennis.raddle at gmail.com Fri Nov 6 07:29:36 2015 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Thu, 5 Nov 2015 23:29:36 -0800 Subject: [Haskell-beginners] mapKeysMaybe Message-ID: Can someone give me a clever way to implement mapKeysMaybe, defined as follows? Ord k => (k -> Maybe k) -> Map k a -> Map k a where the transformed keys that evaluate to Just are the only ones kept? I am thinking this will probably help me understand a new type, like traversable or something. -------------- next part -------------- An HTML attachment was scrubbed... URL: From maydwell at gmail.com Fri Nov 6 07:43:47 2015 From: maydwell at gmail.com (Lyndon Maydwell) Date: Fri, 6 Nov 2015 18:43:47 +1100 Subject: [Haskell-beginners] mapKeysMaybe In-Reply-To: References: Message-ID: Well, this might not be the most efficient, but: mapKeysMaybe f = Data.Map.mapMaybeWithKey (const . f) What do you reckon? On Fri, Nov 6, 2015 at 6:29 PM, Dennis Raddle wrote: > Can someone give me a clever way to implement mapKeysMaybe, defined as > follows? > > Ord k => (k -> Maybe k) -> Map k a -> Map k a > > where the transformed keys that evaluate to Just are the only ones kept? > > I am thinking this will probably help me understand a new type, like > traversable or something. > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From maydwell at gmail.com Fri Nov 6 07:46:40 2015 From: maydwell at gmail.com (Lyndon Maydwell) Date: Fri, 6 Nov 2015 18:46:40 +1100 Subject: [Haskell-beginners] mapKeysMaybe In-Reply-To: References: Message-ID: Oops disregard that. The mapMaybeWithKey doesn't quite do what I expected. On Fri, Nov 6, 2015 at 6:43 PM, Lyndon Maydwell wrote: > Well, this might not be the most efficient, but: > > mapKeysMaybe f = Data.Map.mapMaybeWithKey (const . f) > > > What do you reckon? > > On Fri, Nov 6, 2015 at 6:29 PM, Dennis Raddle > wrote: > >> Can someone give me a clever way to implement mapKeysMaybe, defined as >> follows? >> >> Ord k => (k -> Maybe k) -> Map k a -> Map k a >> >> where the transformed keys that evaluate to Just are the only ones kept? >> >> I am thinking this will probably help me understand a new type, like >> traversable or something. >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From maydwell at gmail.com Fri Nov 6 08:19:03 2015 From: maydwell at gmail.com (Lyndon Maydwell) Date: Fri, 6 Nov 2015 19:19:03 +1100 Subject: [Haskell-beginners] mapKeysMaybe In-Reply-To: References: Message-ID: Here's a more correct solution, unfortunately it's not as nice. {-# LANGUAGE TupleSections #-} import Data.Map hiding (mapMaybe) import Data.Maybe mkm :: Ord k => (t -> Maybe k) -> Map t a -> Map k a mkm f = fromList . mapMaybe (\(k,v) -> fmap (,v) (f k)) . toList On Fri, Nov 6, 2015 at 6:46 PM, Lyndon Maydwell wrote: > Oops disregard that. The mapMaybeWithKey doesn't quite do what I expected. > > On Fri, Nov 6, 2015 at 6:43 PM, Lyndon Maydwell > wrote: > >> Well, this might not be the most efficient, but: >> >> mapKeysMaybe f = Data.Map.mapMaybeWithKey (const . f) >> >> >> What do you reckon? >> >> On Fri, Nov 6, 2015 at 6:29 PM, Dennis Raddle >> wrote: >> >>> Can someone give me a clever way to implement mapKeysMaybe, defined as >>> follows? >>> >>> Ord k => (k -> Maybe k) -> Map k a -> Map k a >>> >>> where the transformed keys that evaluate to Just are the only ones kept? >>> >>> I am thinking this will probably help me understand a new type, like >>> traversable or something. >>> >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From teztingit at gmail.com Fri Nov 6 20:43:02 2015 From: teztingit at gmail.com (goforgit .) Date: Fri, 6 Nov 2015 21:43:02 +0100 Subject: [Haskell-beginners] Add parenthesis to Sin/Cos expressions In-Reply-To: References: Message-ID: Thanlks! On Thu, Nov 5, 2015 at 6:16 PM, Sumit Sahrawat, Maths & Computing, IIT (BHU) wrote: > The spirit of declarative programming lies in the fact that you try to > just tell the compiler what something means. Instead of thinking about > keeping track of the numbers of parentheses, and then applying them > afterwards, I would suggest you create a function to do the same job: > > bracketed :: String -> String > bracketed s = "(" ++ s ++ ")" > > This would allow you to remove the numeric argument, and also write > cleaner code. > > The second thing that you can improve is the pattern matching. You can use > isPrefixOf > to > check functions, or use a take inside a case statement to get cleaner > handling of different cases. > > case take 3 str of > "sin" -> ... > "cos" -> ... > _ -> ... > > This would also let you debug your code more easily, just as you require. > > On 4 November 2015 at 14:51, Imants Cekusins wrote: > >> > a function that is supposed to add parenthesis to sin/cos expressions. >> a) Sin 5 + 3 -> Sin(5) + 3 >> b) Sin Cos (5+3) -> Sin (Cos(5+3)) >> c) Sin Cos 5 * 3 -> Sin(Cos(5)) * 3 >> >> are you looking for textual representation or actual Haskell code which >> runs? >> if actual code, these examples may be re-written like this: >> a) sin 5 + 3 >> b) sin $ cos $ 5 + 3 >> c) sin (cos 5) * 3 >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > > > -- > Regards > > Sumit Sahrawat > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dennis.raddle at gmail.com Fri Nov 6 21:32:36 2015 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Fri, 6 Nov 2015 13:32:36 -0800 Subject: [Haskell-beginners] strict evaluation and MIDI playback Message-ID: I wrote a program in Haskell that does real-time MIDI playback. This involves computing what are called MIDI "events" (things like notes and volume controls) and then using the PortMidi library to play back the events. PortMidi also provides a time reading function that is accurate to 1 millisecond which is useful for timing the playback accurately. I used 'evaluate' in the IO Monad to make sure that all events were fully computed before playback started. However I was still getting delays (timing errors). I added some code to the program that wrote the data to disk before playing it back, and the timing errors went away. Apparently 'evaluate' was not forcing a complete evaluation, while writing a disk file was. Or at least I think that's what happened. But writing to disk is a hack. What can I do to get 'evaluate' to work? A simplified version of the code is here: (the actual program is pretty long and complex so I posted something which is stripped down but I hope retains the essential features) http://lpaste.net/144762 -------------- next part -------------- An HTML attachment was scrubbed... URL: From dennis.raddle at gmail.com Fri Nov 6 21:33:11 2015 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Fri, 6 Nov 2015 13:33:11 -0800 Subject: [Haskell-beginners] mapKeysMaybe In-Reply-To: References: Message-ID: Thanks, Lyndon!? -------------- next part -------------- An HTML attachment was scrubbed... URL: From apfelmus at quantentunnel.de Fri Nov 6 22:22:46 2015 From: apfelmus at quantentunnel.de (Heinrich Apfelmus) Date: Fri, 06 Nov 2015 23:22:46 +0100 Subject: [Haskell-beginners] strict evaluation and MIDI playback In-Reply-To: References: Message-ID: Dear Dennis, note that the `evaluate` function only evaluates to weak head normal form (WHNF). A list may be in WHNF even when the head and tail are unevaluated expressions. What you want is to evaluate the list of notes to normal form (NF). The `Control.DeepSeq` module collects functions related to obtaining normal forms. In your case, changing the line to midiEvents <- evaluate $ force $ computeMidiEvents music will probably do the trick, but you may need to implement an instance NFData for your `MidiEvent` type. For more details on NF, WHNF and lazy evaluation in general, see also [1]. [1]: https://hackhands.com/lazy-evaluation-works-haskell/ Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com Dennis Raddle wrote: > I wrote a program in Haskell that does real-time MIDI playback. This > involves computing what are called MIDI "events" (things like notes and > volume controls) and then using the PortMidi library to play back the > events. PortMidi also provides a time reading function that is accurate to > 1 millisecond which is useful for timing the playback accurately. > > I used 'evaluate' in the IO Monad to make sure that all events were fully > computed before playback started. However I was still getting delays > (timing errors). I added some code to the program that wrote the data to > disk before playing it back, and the timing errors went away. Apparently > 'evaluate' was not forcing a complete evaluation, while writing a disk file > was. Or at least I think that's what happened. > > But writing to disk is a hack. What can I do to get 'evaluate' to work? > > A simplified version of the code is here: (the actual program is pretty > long and complex so I posted something which is stripped down but I hope > retains the essential features) > > http://lpaste.net/144762 > > From dennis.raddle at gmail.com Fri Nov 6 23:26:14 2015 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Fri, 6 Nov 2015 15:26:14 -0800 Subject: [Haskell-beginners] strict evaluation and MIDI playback In-Reply-To: References: Message-ID: ?Thanks! I have a problem though. I read about automatic derivation of an NFData instance. I have GHC version 7.10.2. I tried the code below, but I get Can't make a derived instance of Generic RawMidiEvent You need DeriveGeneric to derive an instance of this class. In the data declaration for 'RawMidiEvent' {-# LANGUAGE DeriveGeneric, DeriveAnyClass #-} import GHC.Generics (Generic) import Control.DeepSeq data RawMidiEvent = RawMidiEvent { rmeStream :: Int , rmeChan :: Int , rmeStatus :: Int , rmeData1 :: Int , rmeData2 :: Int } deriving (Show,Eq,Generic,NFData) -------------- next part -------------- An HTML attachment was scrubbed... URL: From dennis.raddle at gmail.com Fri Nov 6 23:27:42 2015 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Fri, 6 Nov 2015 15:27:42 -0800 Subject: [Haskell-beginners] strict evaluation and MIDI playback In-Reply-To: References: Message-ID: Never mind, I realized that I use the pragma incorrectly -- it wasn't at the top of the module. On Fri, Nov 6, 2015 at 3:26 PM, Dennis Raddle wrote: > > ?Thanks! I have a problem though. I read about automatic derivation of an > NFData instance. I have GHC version 7.10.2. I tried the code below, but I > get > > Can't make a derived instance of Generic RawMidiEvent > You need DeriveGeneric to derive an instance of this class. > In the data declaration for 'RawMidiEvent' > > > {-# LANGUAGE DeriveGeneric, DeriveAnyClass #-} > > import GHC.Generics (Generic) > import Control.DeepSeq > > data RawMidiEvent = RawMidiEvent > { rmeStream :: Int > , rmeChan :: Int > , rmeStatus :: Int > , rmeData1 :: Int > , rmeData2 :: Int > } > deriving (Show,Eq,Generic,NFData) > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dennis.raddle at gmail.com Sat Nov 7 06:07:47 2015 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Fri, 6 Nov 2015 22:07:47 -0800 Subject: [Haskell-beginners] manipulating Map for music application Message-ID: I have a Haskell program that computes music compositions. A composition consists of sounds that happen at locations. A location is data type Loc. At each location is a list of chords. A chord is data type Chord. Each chord contains some chord-specific data and a list of notes. A note is data type Note. So we have data Note = Note ... data Chord = Chord ChordSpecificData [Note] type Composition = Map Loc [Chord] I would like to write a few different functions that operate over all the notes. The following function breaks out all the notes, tupling them with the associated Locs and Chords: compositionToList :: Composition -> [(Loc,Chord,Note)] The following function transforms Notes, keeping only the Just results. If a Chord gets all its notes eliminated, that Chord is removed. If a Loc has all its Chords removed, that Loc is removed from the Map. mapNotesMaybe :: (Loc -> Chord -> Note -> Maybe Note) -> Composition -> Composition Any advice for concise code appreciated. Dennis What's a concise way of doing this? Another useful function would be used for mapping Dennis -------------- next part -------------- An HTML attachment was scrubbed... URL: From chaddai.fouche at gmail.com Sat Nov 7 17:17:23 2015 From: chaddai.fouche at gmail.com (=?UTF-8?B?Q2hhZGRhw68gRm91Y2jDqQ==?=) Date: Sat, 07 Nov 2015 17:17:23 +0000 Subject: [Haskell-beginners] randmomR produces only even values In-Reply-To: References: Message-ID: The System.Random is just not very good, you should not use it if you need something fast or cryptographically secure... But as a first choice for just a few random numbers it's good enough and it was chosen specifically for its capability to split a generator into two, so that's probably what you should be using if you're going to do simulations in parallel with System.Random. Or use random seeds at least ! This is specifically an interaction between random*R* and mkStdGen with low seeds (random don't seem to have this particular flaw), since we're still using a pseudo-random generator, we ought to be pretty careful in the way we use it (those have always been touchy beasts) and this particular usage seems to be a bad counter-example of what to do with a PRNG. If we can improve System.Random to avoid this particular misbehavior we should but using a PRNG in this fashion and hoping for good randomness from the result is probably a bad idea in the first place. Le mer. 4 nov. 2015 ? 11:00, Dominic Steinitz a ?crit : > > http://article.gmane.org/gmane.comp.lang.haskell.beginners/15925 > > I do think this is a flaw and catches many people out despite apparently > being well documented. And it's something one probably wants e.g. to run > multiple Markov Chain Monte Carlo simulations in parallel. > > Some further information here: > https://github.com/haskell/random/issues/30#issuecomment-153647055 > > Dominic > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From chaddai.fouche at gmail.com Sat Nov 7 17:41:38 2015 From: chaddai.fouche at gmail.com (=?UTF-8?B?Q2hhZGRhw68gRm91Y2jDqQ==?=) Date: Sat, 07 Nov 2015 17:41:38 +0000 Subject: [Haskell-beginners] manipulating Map for music application In-Reply-To: References: Message-ID: This is a bit tricky but mapMaybeWithKey is clearly the tool for the job : > mapMaybeWithKey :: (k -> a -> Maybe b) -> Map k a -> Map k b So : mapNotesMaybe :: (Loc -> Chord -> Note -> Maybe Note) -> Composition -> Composition mapNotesMaybe f compo = mapMaybeWithKey go compo where go loc chords = mconcat . map (gogo loc) $ chords gogo loc chord = mconcat . map (fmap pure . f loc chord) $ chord This should work. -- Chadda? Le sam. 7 nov. 2015 ? 07:07, Dennis Raddle a ?crit : > I have a Haskell program that computes music compositions. A composition > consists of sounds that happen at locations. A location is data type Loc. > At each location is a list of chords. A chord is data type Chord. Each > chord contains some chord-specific data and a list of notes. A note is data > type Note. > > So we have > > data Note = Note ... > data Chord = Chord ChordSpecificData [Note] > type Composition = Map Loc [Chord] > > I would like to write a few different functions that operate over all the > notes. > > The following function breaks out all the notes, tupling them with the > associated Locs and Chords: > compositionToList :: Composition -> [(Loc,Chord,Note)] > > The following function transforms Notes, keeping only the Just results. If > a Chord gets all its notes eliminated, that Chord is removed. If a Loc has > all its Chords removed, that Loc is removed from the Map. > mapNotesMaybe :: (Loc -> Chord -> Note -> Maybe Note) -> Composition > -> Composition > > Any advice for concise code appreciated. > Dennis > > > What's a concise way of doing this? > > Another useful function would be used for mapping > > Dennis > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From chaddai.fouche at gmail.com Sat Nov 7 17:47:47 2015 From: chaddai.fouche at gmail.com (=?UTF-8?B?Q2hhZGRhw68gRm91Y2jDqQ==?=) Date: Sat, 07 Nov 2015 17:47:47 +0000 Subject: [Haskell-beginners] manipulating Map for music application In-Reply-To: References: Message-ID: Ooops forgot that Chords are not just lists of Notes : mapNotesMaybe f compo = mapMaybeWithKey go compo where go loc chords = mconcat . map (fmap (:[]) . gogo loc) $ chords gogo loc chord@(Chord d notes) = fmap (Chord d) . mconcat . map (fmap (:[]) . f loc chord) $ notes Le sam. 7 nov. 2015 ? 18:41, Chadda? Fouch? a ?crit : > This is a bit tricky but mapMaybeWithKey is clearly the tool for the job : > > > mapMaybeWithKey :: (k -> a -> Maybe > > b) -> Map > > k a -> Map > > k b > > So : > > > mapNotesMaybe :: (Loc -> Chord -> Note -> Maybe Note) -> Composition -> > Composition > mapNotesMaybe f compo = mapMaybeWithKey go compo > where > go loc chords = mconcat . map (gogo loc) $ chords > gogo loc chord = mconcat . map (fmap pure . f loc chord) $ chord > > This should work. > > -- > Chadda? > > > Le sam. 7 nov. 2015 ? 07:07, Dennis Raddle a > ?crit : > >> I have a Haskell program that computes music compositions. A composition >> consists of sounds that happen at locations. A location is data type Loc. >> At each location is a list of chords. A chord is data type Chord. Each >> chord contains some chord-specific data and a list of notes. A note is data >> type Note. >> >> So we have >> >> data Note = Note ... >> data Chord = Chord ChordSpecificData [Note] >> type Composition = Map Loc [Chord] >> >> I would like to write a few different functions that operate over all the >> notes. >> >> The following function breaks out all the notes, tupling them with the >> associated Locs and Chords: >> compositionToList :: Composition -> [(Loc,Chord,Note)] >> >> The following function transforms Notes, keeping only the Just results. >> If a Chord gets all its notes eliminated, that Chord is removed. If a Loc >> has all its Chords removed, that Loc is removed from the Map. >> mapNotesMaybe :: (Loc -> Chord -> Note -> Maybe Note) -> Composition >> -> Composition >> >> Any advice for concise code appreciated. >> Dennis >> >> >> What's a concise way of doing this? >> >> Another useful function would be used for mapping >> >> Dennis >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Sat Nov 7 21:56:43 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Sat, 7 Nov 2015 22:56:43 +0100 Subject: [Haskell-beginners] is this not a better way ? data structure Message-ID: <563E739B.9080202@home.nl> Hello, In the book there is a example of this data-structure. data Shape = Circle float float | Rectangle float float Now I have to change it to add a center point. But I wonder if this is not a better way to describe it Data Schape = Circle Radius | Rectangle Width Height Type Radius = Float type Width = Float type Height = Float Roelof From i.caught.air at gmail.com Sat Nov 7 22:03:11 2015 From: i.caught.air at gmail.com (Alex Belanger) Date: Sat, 7 Nov 2015 17:03:11 -0500 Subject: [Haskell-beginners] is this not a better way ? data structure In-Reply-To: <563E739B.9080202@home.nl> References: <563E739B.9080202@home.nl> Message-ID: I feel the latter example serves only documentation purposes. Maybe describe what those floats are in the former example and you can ignore the extra type aliases entirely. Introducing a new concern for your module/application when it appears only once might just add extra complexity. Of course, as the codebase grows and this datatype evolves, you'll probably want to go that route, but until then, I think it's preemptively unecessery. - nitrix On Nov 7, 2015 4:56 PM, "Roelof Wobben" wrote: > Hello, > > In the book there is a example of this data-structure. > > data Shape = Circle float float > | Rectangle float float > > Now I have to change it to add a center point. > > But I wonder if this is not a better way to describe it > > Data Schape = Circle Radius > | Rectangle Width Height > > Type Radius = Float > type Width = Float > type Height = Float > > Roelof > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Sat Nov 7 22:32:29 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Sat, 7 Nov 2015 23:32:29 +0100 Subject: [Haskell-beginners] is this not a better way ? data structure In-Reply-To: References: <563E739B.9080202@home.nl> Message-ID: <563E7BFD.6060400@home.nl> An HTML attachment was scrubbed... URL: From dennis.raddle at gmail.com Sat Nov 7 23:01:09 2015 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Sat, 7 Nov 2015 15:01:09 -0800 Subject: [Haskell-beginners] manipulating Map for music application In-Reply-To: References: Message-ID: Thanks! I'm a Haskell beginner and will relish the opportunity to learn more by studying your code. On Sat, Nov 7, 2015 at 9:47 AM, Chadda? Fouch? wrote: > Ooops forgot that Chords are not just lists of Notes : > > mapNotesMaybe f compo = mapMaybeWithKey go compo > where > go loc chords = mconcat . map (fmap (:[]) . gogo loc) $ chords > gogo loc chord@(Chord d notes) = fmap (Chord d) . mconcat . map (fmap > (:[]) . f loc chord) $ notes > > Le sam. 7 nov. 2015 ? 18:41, Chadda? Fouch? a > ?crit : > >> This is a bit tricky but mapMaybeWithKey is clearly the tool for the job : >> >> > mapMaybeWithKey :: (k -> a -> Maybe >> >> b) -> Map >> >> k a -> Map >> >> k b >> >> So : >> >> >> mapNotesMaybe :: (Loc -> Chord -> Note -> Maybe Note) -> Composition -> >> Composition >> mapNotesMaybe f compo = mapMaybeWithKey go compo >> where >> go loc chords = mconcat . map (gogo loc) $ chords >> gogo loc chord = mconcat . map (fmap pure . f loc chord) $ chord >> >> This should work. >> >> -- >> Chadda? >> >> >> Le sam. 7 nov. 2015 ? 07:07, Dennis Raddle a >> ?crit : >> >>> I have a Haskell program that computes music compositions. A composition >>> consists of sounds that happen at locations. A location is data type Loc. >>> At each location is a list of chords. A chord is data type Chord. Each >>> chord contains some chord-specific data and a list of notes. A note is data >>> type Note. >>> >>> So we have >>> >>> data Note = Note ... >>> data Chord = Chord ChordSpecificData [Note] >>> type Composition = Map Loc [Chord] >>> >>> I would like to write a few different functions that operate over all >>> the notes. >>> >>> The following function breaks out all the notes, tupling them with the >>> associated Locs and Chords: >>> compositionToList :: Composition -> [(Loc,Chord,Note)] >>> >>> The following function transforms Notes, keeping only the Just results. >>> If a Chord gets all its notes eliminated, that Chord is removed. If a Loc >>> has all its Chords removed, that Loc is removed from the Map. >>> mapNotesMaybe :: (Loc -> Chord -> Note -> Maybe Note) -> Composition >>> -> Composition >>> >>> Any advice for concise code appreciated. >>> Dennis >>> >>> >>> What's a concise way of doing this? >>> >>> Another useful function would be used for mapping >>> >>> Dennis >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >> > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeffbrown.the at gmail.com Sun Nov 8 06:14:58 2015 From: jeffbrown.the at gmail.com (Jeffrey Brown) Date: Sat, 7 Nov 2015 22:14:58 -0800 Subject: [Haskell-beginners] Why does floor not consider its argument an Integral? Message-ID: Tidal [1] defines these data types: type Time = Rational type Arc = (Time, Time) I want to write a function "splitMultiCycArc" which divides an Arc into mostly-integer segments, so that, for instance, splitMultiCycArc (0,1) = [(0,1)] splitMultiCycArc (0,2) = [(0,1),(1,2)] splitMultiCycArc (0,3) = [(0,1),(1,2),(2,3)] splitMultiCycArc (1%2,2) = [(1%2,1),(1,2)] splitMultiCycArc (1,5%2) = [(1,2),(2,5%2)] I thought I had solved the problem with this code: splitMultiCycArc:: Arc -> [Arc] splitMultiCycArc (a,b) = let ceiling_ish = floor a + 1 in if b <= a then [] else if b <= ceiling_ish then [(a,b)] else (a,ceiling_ish) : splitMultiCycArc (ceiling_ish,b) When I try to load that, I get this single error: > :reload [12 of 13] Compiling Sound.Tidal.JBB ( Sound/Tidal/JBB.hs, interpreted ) Sound/Tidal/JBB.hs:16:44: No instance for (Integral Time) arising from a use of ?floor? In the first argument of ?(+)?, namely ?floor a? In the expression: floor a + 1 In an equation for ?ceiling_ish?: ceiling_ish = floor a + 1 Failed, modules loaded: Sound.Tidal.Strategies, Sound.Tidal.Dirt, Sound.Tidal.Pattern, Sound.Tidal.Stream, Sound.Tidal.Parse, Sound.Tidal.Tempo, Sound.Tidal.Time, Sound.Tidal.Utils, Sound.Tidal.SuperCollider, Sound.Tidal.Params, Sound.Tidal.Transition. > And yet under other conditions, "floor" is perfectly happy operating on a Time value: > let a = (1%2,1) :: Arc > floor (fst a) + 1 1 > [1] https://hackage.haskell.org/package/tidal -- Jeffrey Benjamin Brown -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeffbrown.the at gmail.com Sun Nov 8 07:10:17 2015 From: jeffbrown.the at gmail.com (Jeffrey Brown) Date: Sat, 7 Nov 2015 23:10:17 -0800 Subject: [Haskell-beginners] Why does floor not consider its argument an Integral? In-Reply-To: References: Message-ID: I solved it. I was misreading the error report as being about the input to floor, when the problem was the output of it. This code works: splitArcAtIntegers:: Arc -> [Arc] splitArcAtIntegers (a,b) = let ceiling_ish = fromInteger $ (floor a) + 1 in if b <= a then [] else if b <= ceiling_ish then [(a,b)] else (a,ceiling_ish) : splitArcAtIntegers (ceiling_ish,b) On Sat, Nov 7, 2015 at 10:14 PM, Jeffrey Brown wrote: > Tidal [1] defines these data types: > > type Time = Rational > type Arc = (Time, Time) > > I want to write a function "splitMultiCycArc" which divides an Arc into > mostly-integer segments, so that, for instance, > > splitMultiCycArc (0,1) = [(0,1)] > splitMultiCycArc (0,2) = [(0,1),(1,2)] > splitMultiCycArc (0,3) = [(0,1),(1,2),(2,3)] > splitMultiCycArc (1%2,2) = [(1%2,1),(1,2)] > splitMultiCycArc (1,5%2) = [(1,2),(2,5%2)] > > I thought I had solved the problem with this code: > > splitMultiCycArc:: Arc -> [Arc] > splitMultiCycArc (a,b) = let ceiling_ish = floor a + 1 in > if b <= a then [] > else if b <= ceiling_ish then [(a,b)] > else (a,ceiling_ish) : splitMultiCycArc (ceiling_ish,b) > > When I try to load that, I get this single error: > > > :reload > [12 of 13] Compiling Sound.Tidal.JBB ( Sound/Tidal/JBB.hs, > interpreted ) > > Sound/Tidal/JBB.hs:16:44: > No instance for (Integral Time) arising from a use of ?floor? > In the first argument of ?(+)?, namely ?floor a? > In the expression: floor a + 1 > In an equation for ?ceiling_ish?: ceiling_ish = floor a + 1 > Failed, modules loaded: Sound.Tidal.Strategies, Sound.Tidal.Dirt, > Sound.Tidal.Pattern, Sound.Tidal.Stream, Sound.Tidal.Parse, > Sound.Tidal.Tempo, Sound.Tidal.Time, Sound.Tidal.Utils, > Sound.Tidal.SuperCollider, Sound.Tidal.Params, Sound.Tidal.Transition. > > > > And yet under other conditions, "floor" is perfectly happy operating on a > Time value: > > > let a = (1%2,1) :: Arc > > floor (fst a) + 1 > 1 > > > > [1] https://hackage.haskell.org/package/tidal > > > -- > Jeffrey Benjamin Brown > -- Jeffrey Benjamin Brown -------------- next part -------------- An HTML attachment was scrubbed... URL: From frederic-emmanuel.picca at synchrotron-soleil.fr Sun Nov 8 09:55:30 2015 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Sun, 8 Nov 2015 09:55:30 +0000 Subject: [Haskell-beginners] ffi array and peekArray In-Reply-To: References: Message-ID: Hello, Here the signature of one of my C function -- hkl.h -- typedef struct _HklFactory HklFactory; HKLAPI HklFactory **hkl_factory_get_all(size_t *n) HKL_ARG_NONNULL(1); HKLAPI HklFactory *hkl_factory_get_by_name(const char *name, GError **error) HKL_ARG_NONNULL(1) HKL_WARN_UNUSED_RESULT; HKLAPI const char *hkl_factory_name_get(const HklFactory *self) HKL_ARG_NONNULL(1); HKLAPI HklGeometry *hkl_factory_create_new_geometry(const HklFactory *self) HKL_ARG_NONNULL(1); HKLAPI HklEngineList *hkl_factory_create_new_engine_list(const HklFactory *self) HKL_ARG_NONNULL(1); I will focuss for now only the get_all method. As you can see even for the C client of my API HklFactory is an opac struct This get_all method return an array of (HklFactory *) and get the size of the array via the n parameter. So I am trying to use this API from haskell with the foreign system and return a [HklFactory] import Foreign (Ptr, peek) import Foreign.Marshal.Alloc (alloca) import Foreign.Marshal.Array (peekArray) data HklFactory foreign import ccall safe "hkl.h hkl_factory_get_all" c_hkl_factory_get_all :: Ptr Int -> IO (Ptr HklFactory) hklFactoryGetAll :: IO [HklFactory] hklFactoryGetAll = alloca $ \n -> do factories <- c_hkl_factory_get_all n peekArray n factories but indeed it doesn not work, peekArray complain that n is Ptr Int instead of Int. what should I do in order to get my array of HklFactory thanks for your help. Frederic From olivier.tournaire at wanadoo.fr Sun Nov 8 09:56:38 2015 From: olivier.tournaire at wanadoo.fr (Olivier TOURNAIRE) Date: Sun, 8 Nov 2015 10:56:38 +0100 (CET) Subject: [Haskell-beginners] (no subject) Message-ID: <860188405.2807.1446976598088.JavaMail.www@wwinf1j16> Hello I would like to implement Haskell with a samsung tablet SM T800. How can i do that ? Thank you very much. From imantc at gmail.com Sun Nov 8 10:17:27 2015 From: imantc at gmail.com (Imants Cekusins) Date: Sun, 8 Nov 2015 11:17:27 +0100 Subject: [Haskell-beginners] (no subject) In-Reply-To: <860188405.2807.1446976598088.JavaMail.www@wwinf1j16> References: <860188405.2807.1446976598088.JavaMail.www@wwinf1j16> Message-ID: > Haskell with a samsung tablet SM T800. The short answer: this is not easy. Here is some detail: https://wiki.haskell.org/Android -------------- next part -------------- An HTML attachment was scrubbed... URL: From hsyl20 at gmail.com Sun Nov 8 17:34:52 2015 From: hsyl20 at gmail.com (Sylvain Henry) Date: Sun, 8 Nov 2015 18:34:52 +0100 Subject: [Haskell-beginners] ffi array and peekArray In-Reply-To: References: Message-ID: Hi, you have to peek the pointed value. Something like: hklFactoryGetAll :: IO [HklFactory] hklFactoryGetAll = alloca $ \ptrn -> do factories <- c_hkl_factory_get_all ptrn n <- peek ptrn peekArray n factories 2015-11-08 10:55 GMT+01:00 PICCA Frederic-Emmanuel < frederic-emmanuel.picca at synchrotron-soleil.fr>: > Hello, > > Here the signature of one of my C function > > -- hkl.h -- > > typedef struct _HklFactory HklFactory; > > HKLAPI HklFactory **hkl_factory_get_all(size_t *n) HKL_ARG_NONNULL(1); > > HKLAPI HklFactory *hkl_factory_get_by_name(const char *name, > GError **error) > HKL_ARG_NONNULL(1) HKL_WARN_UNUSED_RESULT; > > HKLAPI const char *hkl_factory_name_get(const HklFactory *self) > HKL_ARG_NONNULL(1); > > HKLAPI HklGeometry *hkl_factory_create_new_geometry(const HklFactory > *self) HKL_ARG_NONNULL(1); > > HKLAPI HklEngineList *hkl_factory_create_new_engine_list(const HklFactory > *self) HKL_ARG_NONNULL(1); > > > I will focuss for now only the get_all method. As you can see even for the > C client of my API HklFactory is an opac struct > This get_all method return an array of (HklFactory *) and get the size of > the array via the n parameter. > > So I am trying to use this API from haskell with the foreign system and > return a [HklFactory] > > import Foreign (Ptr, peek) > import Foreign.Marshal.Alloc (alloca) > import Foreign.Marshal.Array (peekArray) > > data HklFactory > > foreign import ccall safe "hkl.h hkl_factory_get_all" > c_hkl_factory_get_all :: Ptr Int -> IO (Ptr HklFactory) > > hklFactoryGetAll :: IO [HklFactory] > hklFactoryGetAll = alloca $ \n -> do > factories <- c_hkl_factory_get_all n > peekArray n factories > > > but indeed it doesn not work, peekArray complain that n is Ptr Int instead > of Int. > > what should I do in order to get my array of HklFactory > > thanks for your help. > > > Frederic > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From frederic-emmanuel.picca at synchrotron-soleil.fr Sun Nov 8 20:30:13 2015 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Sun, 8 Nov 2015 20:30:13 +0000 Subject: [Haskell-beginners] ffi array and peekArray In-Reply-To: References: , Message-ID: Ok, so now I get this error ghkl.hs:20:18: No instance for (Foreign.Storable.Storable HklFactory) arising from a use of ?peekArray? In a stmt of a 'do' block: peekArray n factories In the expression: do { factories <- c_hkl_factory_get_all ptr; n <- peek ptr; peekArray n factories } In the second argument of ?($)?, namely ?\ ptr -> do { factories <- c_hkl_factory_get_all ptr; n <- peek ptr; .... }? What should I do to create a Storable for HklFactory which is a simple pointer. Thanks Frederic From hsyl20 at gmail.com Sun Nov 8 20:45:39 2015 From: hsyl20 at gmail.com (Sylvain Henry) Date: Sun, 8 Nov 2015 21:45:39 +0100 Subject: [Haskell-beginners] ffi array and peekArray In-Reply-To: References: Message-ID: You can alias HklFactory: type HklFactory = Ptr () Or if you want to avoid mixing HklFactory and other pointers, you can use: newtype HklFactory = HklFactory (Ptr ()) deriving (Storable) The latter requires the GeneralizedNewtypeDeriving extension, see: https://wiki.haskell.org/Foreign_Function_Interface#Renaming_and_Storable_instances Sylvain 2015-11-08 21:30 GMT+01:00 PICCA Frederic-Emmanuel < frederic-emmanuel.picca at synchrotron-soleil.fr>: > Ok, so now I get this error > > > ghkl.hs:20:18: > No instance for (Foreign.Storable.Storable HklFactory) > arising from a use of ?peekArray? > In a stmt of a 'do' block: peekArray n factories > In the expression: > do { factories <- c_hkl_factory_get_all ptr; > n <- peek ptr; > peekArray n factories } > In the second argument of ?($)?, namely > ?\ ptr > -> do { factories <- c_hkl_factory_get_all ptr; > n <- peek ptr; > .... }? > > > What should I do to create a Storable for HklFactory which is a simple > pointer. > > Thanks > > Frederic > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From c.venu at aol.com Mon Nov 9 04:14:11 2015 From: c.venu at aol.com (Venu Chakravorty) Date: Sun, 8 Nov 2015 23:14:11 -0500 Subject: [Haskell-beginners] Calling "zipWith" using "^" function. Message-ID: <150ea73896a-2a1f-69dc@webprd-a18.mail.aol.com> Hello there, This is just some toy program I was trying. I fail to understand why this works: ============================= Prelude> zipWith (\ x y -> ((x ^ y) / (product [1..x]))) [1..3] [2,2,2] [1.0,2.0,1.5] ============================= and this does not: ============================= Prelude> zipWith (\ x y -> ((y ^ x) / (product [1..x]))) [1..3] [2,2,2] :1:19: Ambiguous type variable `a' in the constraints: `Fractional a' arising from a use of `/' at :1:19-44 `Integral a' arising from a use of `^' at :1:20-24 Probable fix: add a type signature that fixes these type variable(s) ============================ Note that the "^" function has "x" and "y" flipped. :t (^) says: ============================ (^) :: (Num a, Integral b) => a -> b -> a ============================ Could somebody please throw some light? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From zhiwudazhanjiangshi at gmail.com Mon Nov 9 04:28:14 2015 From: zhiwudazhanjiangshi at gmail.com (yi lu) Date: Mon, 9 Nov 2015 12:28:14 +0800 Subject: [Haskell-beginners] Calling "zipWith" using "^" function. In-Reply-To: <150ea73896a-2a1f-69dc@webprd-a18.mail.aol.com> References: <150ea73896a-2a1f-69dc@webprd-a18.mail.aol.com> Message-ID: Prelude> :t (**) (**) :: Floating a => a -> a -> a On Mon, Nov 9, 2015 at 12:14 PM, Venu Chakravorty wrote: > Hello there, > This is just some toy program I was trying. I fail to understand why this > works: > > ============================= > Prelude> zipWith (\ x y -> ((x ^ y) / (product [1..x]))) [1..3] [2,2,2] > [1.0,2.0,1.5] > ============================= > > and this does not: > > ============================= > Prelude> zipWith (\ x y -> ((y ^ x) / (product [1..x]))) [1..3] [2,2,2] > > :1:19: > Ambiguous type variable `a' in the constraints: > `Fractional a' arising from a use of `/' at :1:19-44 > `Integral a' arising from a use of `^' at :1:20-24 > Probable fix: add a type signature that fixes these type variable(s) > ============================ > Note that the "^" function has "x" and "y" flipped. > > :t (^) says: > ============================ > (^) :: (Num a, Integral b) => a -> b -> a > ============================ > > Could somebody please throw some light? > > Thanks. > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From max.voit+mlhb at with-eyes.net Mon Nov 9 08:59:25 2015 From: max.voit+mlhb at with-eyes.net (Max Voit) Date: Mon, 9 Nov 2015 09:59:25 +0100 Subject: [Haskell-beginners] Calling "zipWith" using "^" function. In-Reply-To: <150ea73896a-2a1f-69dc@webprd-a18.mail.aol.com> References: <150ea73896a-2a1f-69dc@webprd-a18.mail.aol.com> Message-ID: <20151109095925.17d65a8c@veeloqu.lan> On Sun, 8 Nov 2015 23:14:11 -0500 Venu Chakravorty wrote: > :1:19: > Ambiguous type variable `a' in the constraints: > `Fractional a' arising from a use of `/' at > :1:19-44 `Integral a' arising from a use of `^' at > :1:20-24 Probable fix: add a type signature that fixes > these type variable(s) ============================ > Could somebody please throw some light? Consider the types of both (^) and (/). Then take a look at https://www.haskell.org/onlinereport/haskell2010/haskell2x.png and compare with your error message. Note especially that there is no connection from Integral to Fractional or vice versa. As a solution use either the already suggested (**) or fromIntegral (mind the last subsection of https://www.haskell.org/onlinereport/haskell2010/haskellch6.html ) best, Max From strombrg at gmail.com Tue Nov 10 02:07:49 2015 From: strombrg at gmail.com (Dan Stromberg) Date: Mon, 9 Nov 2015 18:07:49 -0800 Subject: [Haskell-beginners] Python's collections.defaultdict(list) in Haskell? Message-ID: I'm spending a little time here and there to learn some Haskell. I'm coming from a chiefly Python/C/bash background. I want to build a Data.Map where the keys are strings, and the values are lists of strings. In Python, collections.defaultdict(list) makes this pretty straightforward. It gives a hash table ("dict") that has values that default to an empty list, since list() produces an empty list. More info here: https://docs.python.org/3/library/collections.html#collections.defaultdict Is there an equivalent in Haskell? Thanks! -- Dan Stromberg -------------- next part -------------- An HTML attachment was scrubbed... URL: From hsyl20 at gmail.com Tue Nov 10 03:45:54 2015 From: hsyl20 at gmail.com (Sylvain Henry) Date: Tue, 10 Nov 2015 04:45:54 +0100 Subject: [Haskell-beginners] Python's collections.defaultdict(list) in Haskell? In-Reply-To: References: Message-ID: import qualified Data.Map as Map -- if your keys are unique let xs = [("Item0", ["a","b","c"]), ("Item1", ["x","y"]), ("Item2", ["abc","def"])] Map.fromList xs -- if you want to combine values for keys that are equal let xs = [("Item0", ["a","b","c"]), ("Item1", ["x","y"]), ("Item0", ["abc","def"])] Map.fromListWith (++) xs -- Sylvain 2015-11-10 3:07 GMT+01:00 Dan Stromberg : > > I'm spending a little time here and there to learn some Haskell. I'm > coming from a chiefly Python/C/bash background. > > I want to build a Data.Map where the keys are strings, and the values are > lists of strings. > > In Python, collections.defaultdict(list) makes this pretty > straightforward. It gives a hash table ("dict") that has values that > default to an empty list, since list() produces an empty list. More info > here: > https://docs.python.org/3/library/collections.html#collections.defaultdict > > Is there an equivalent in Haskell? > > Thanks! > > -- > Dan Stromberg > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From strombrg at gmail.com Tue Nov 10 05:23:27 2015 From: strombrg at gmail.com (Dan Stromberg) Date: Mon, 9 Nov 2015 21:23:27 -0800 Subject: [Haskell-beginners] Python's collections.defaultdict(list) in Haskell? In-Reply-To: References: Message-ID: These are some good leads. I'll be adding values one at a time, and yes, my keys aren't necessarily unique. Is there a way of cons'ing on the single values one at a time, that will avoid the slowness of ++ ? Thanks. On Mon, Nov 9, 2015 at 7:45 PM, Sylvain Henry wrote: > import qualified Data.Map as Map > > -- if your keys are unique > let xs = [("Item0", ["a","b","c"]), ("Item1", ["x","y"]), ("Item2", > ["abc","def"])] > Map.fromList xs > > -- if you want to combine values for keys that are equal > let xs = [("Item0", ["a","b","c"]), ("Item1", ["x","y"]), ("Item0", > ["abc","def"])] > Map.fromListWith (++) xs > > -- > Sylvain > > > 2015-11-10 3:07 GMT+01:00 Dan Stromberg : > >> >> I'm spending a little time here and there to learn some Haskell. I'm >> coming from a chiefly Python/C/bash background. >> >> I want to build a Data.Map where the keys are strings, and the values are >> lists of strings. >> >> In Python, collections.defaultdict(list) makes this pretty >> straightforward. It gives a hash table ("dict") that has values that >> default to an empty list, since list() produces an empty list. More info >> here: >> https://docs.python.org/3/library/collections.html#collections.defaultdict >> >> Is there an equivalent in Haskell? >> >> Thanks! >> >> -- >> Dan Stromberg >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Dan Stromberg -------------- next part -------------- An HTML attachment was scrubbed... URL: From hsyl20 at gmail.com Tue Nov 10 13:24:35 2015 From: hsyl20 at gmail.com (Sylvain Henry) Date: Tue, 10 Nov 2015 14:24:35 +0100 Subject: [Haskell-beginners] Python's collections.defaultdict(list) in Haskell? In-Reply-To: References: Message-ID: You can use insertWith: http://hackage.haskell.org/package/containers-0.5.6.3/docs/Data-Map-Strict.html#g:6 E.g.: let xs = [("Item0", ["a","b","c"]), ("Item1", ["x","y"])] let m = Map.fromList xs Map.insertWith (++) "Item0" ["d"] m "d" is cons'ed from the left, so it shouldn't be too slow. I don't know why insertWith has this type instead of: Ord k => (b -> a -> a) -> k -> b -> Map k a -> Map k a which would allow you to write Map.insertWith (:) "Item0" "d" m Maybe you should report it. -- Sylvain 2015-11-10 6:23 GMT+01:00 Dan Stromberg : > > These are some good leads. > > I'll be adding values one at a time, and yes, my keys aren't necessarily > unique. > > Is there a way of cons'ing on the single values one at a time, that will > avoid the slowness of ++ ? > > Thanks. > > On Mon, Nov 9, 2015 at 7:45 PM, Sylvain Henry wrote: > >> import qualified Data.Map as Map >> >> -- if your keys are unique >> let xs = [("Item0", ["a","b","c"]), ("Item1", ["x","y"]), ("Item2", >> ["abc","def"])] >> Map.fromList xs >> >> -- if you want to combine values for keys that are equal >> let xs = [("Item0", ["a","b","c"]), ("Item1", ["x","y"]), ("Item0", >> ["abc","def"])] >> Map.fromListWith (++) xs >> >> -- >> Sylvain >> >> >> 2015-11-10 3:07 GMT+01:00 Dan Stromberg : >> >>> >>> I'm spending a little time here and there to learn some Haskell. I'm >>> coming from a chiefly Python/C/bash background. >>> >>> I want to build a Data.Map where the keys are strings, and the values >>> are lists of strings. >>> >>> In Python, collections.defaultdict(list) makes this pretty >>> straightforward. It gives a hash table ("dict") that has values that >>> default to an empty list, since list() produces an empty list. More info >>> here: >>> https://docs.python.org/3/library/collections.html#collections.defaultdict >>> >>> Is there an equivalent in Haskell? >>> >>> Thanks! >>> >>> -- >>> Dan Stromberg >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > > -- > Dan Stromberg > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hsyl20 at gmail.com Tue Nov 10 13:30:15 2015 From: hsyl20 at gmail.com (Sylvain Henry) Date: Tue, 10 Nov 2015 14:30:15 +0100 Subject: [Haskell-beginners] Python's collections.defaultdict(list) in Haskell? In-Reply-To: References: Message-ID: Oh forget the last part of my email: if the key doesn't exist, insertWith has to insert the new value, hence its type... -- Sylvain 2015-11-10 14:24 GMT+01:00 Sylvain Henry : > You can use insertWith: > http://hackage.haskell.org/package/containers-0.5.6.3/docs/Data-Map-Strict.html#g:6 > > E.g.: > let xs = [("Item0", ["a","b","c"]), ("Item1", ["x","y"])] > let m = Map.fromList xs > Map.insertWith (++) "Item0" ["d"] m > > "d" is cons'ed from the left, so it shouldn't be too slow. I don't know > why insertWith has this type instead of: > Ord k => (b -> a -> a) -> k -> b -> Map k a -> Map k a > which would allow you to write Map.insertWith (:) "Item0" "d" m > > Maybe you should report it. > > -- > Sylvain > > 2015-11-10 6:23 GMT+01:00 Dan Stromberg : > >> >> These are some good leads. >> >> I'll be adding values one at a time, and yes, my keys aren't necessarily >> unique. >> >> Is there a way of cons'ing on the single values one at a time, that will >> avoid the slowness of ++ ? >> >> Thanks. >> >> On Mon, Nov 9, 2015 at 7:45 PM, Sylvain Henry wrote: >> >>> import qualified Data.Map as Map >>> >>> -- if your keys are unique >>> let xs = [("Item0", ["a","b","c"]), ("Item1", ["x","y"]), ("Item2", >>> ["abc","def"])] >>> Map.fromList xs >>> >>> -- if you want to combine values for keys that are equal >>> let xs = [("Item0", ["a","b","c"]), ("Item1", ["x","y"]), ("Item0", >>> ["abc","def"])] >>> Map.fromListWith (++) xs >>> >>> -- >>> Sylvain >>> >>> >>> 2015-11-10 3:07 GMT+01:00 Dan Stromberg : >>> >>>> >>>> I'm spending a little time here and there to learn some Haskell. I'm >>>> coming from a chiefly Python/C/bash background. >>>> >>>> I want to build a Data.Map where the keys are strings, and the values >>>> are lists of strings. >>>> >>>> In Python, collections.defaultdict(list) makes this pretty >>>> straightforward. It gives a hash table ("dict") that has values that >>>> default to an empty list, since list() produces an empty list. More info >>>> here: >>>> https://docs.python.org/3/library/collections.html#collections.defaultdict >>>> >>>> Is there an equivalent in Haskell? >>>> >>>> Thanks! >>>> >>>> -- >>>> Dan Stromberg >>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>>> >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> >> >> -- >> Dan Stromberg >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Wed Nov 11 12:59:23 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Wed, 11 Nov 2015 13:59:23 +0100 Subject: [Haskell-beginners] assistance please ? Message-ID: <56433BAB.5030408@home.nl> Hello, I have this exercise : Define a function fibTable :: Integer -> String which produces a table of Fibonacci numbers. For instance, the effect of putStr (fibTable 6) should be n fib n 0 0 1 1 2 1 3 2 4 3 5 5 6 8 1) Can somone give me any pointers how to calculate the fibb numbers with list comprehension. I know that the fib numbers are (n -1) + n 2) Can someone give me any pointers how to write the outcome of every run Roelof From sumit.sahrawat.apm13 at iitbhu.ac.in Wed Nov 11 13:11:13 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Wed, 11 Nov 2015 18:41:13 +0530 Subject: [Haskell-beginners] assistance please ? In-Reply-To: <56433BAB.5030408@home.nl> References: <56433BAB.5030408@home.nl> Message-ID: Hint 1) fib n = fib (n - 1) + fib (n - 2), with proper base cases Hint 2) use mapM_ to print a list of pairs, where the list is created by zipping [1..] with the list of fibonacci numbers On 11 November 2015 at 18:29, Roelof Wobben wrote: > Hello, > > I have this exercise : > > Define a function > fibTable :: Integer -> String > which produces a table of Fibonacci numbers. For instance, the effect of > putStr > (fibTable 6) should be > n fib n > 0 0 > 1 1 > 2 1 > 3 2 > 4 3 > 5 5 > 6 8 > > > > 1) Can somone give me any pointers how to calculate the fibb numbers with > list comprehension. > I know that the fib numbers are (n -1) + n > > 2) Can someone give me any pointers how to write the outcome of every run > > Roelof > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Wed Nov 11 13:27:46 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Wed, 11 Nov 2015 14:27:46 +0100 Subject: [Haskell-beginners] assistance please ? In-Reply-To: References: <56433BAB.5030408@home.nl> Message-ID: <56434252.10701@home.nl> An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Wed Nov 11 13:33:16 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Wed, 11 Nov 2015 19:03:16 +0530 Subject: [Haskell-beginners] assistance please ? In-Reply-To: <56434252.10701@home.nl> References: <56433BAB.5030408@home.nl> <56434252.10701@home.nl> Message-ID: You can do something like fibTable n = [ show x ++ "\t" ++ show y | (x,y) <- zip [1..] (fibs n) ] where fibs n = list containing fibonacci numbers from fib(1) to fib(n) On 11 November 2015 at 18:57, Roelof Wobben wrote: > Op 11-11-2015 om 14:11 schreef Sumit Sahrawat, Maths & Computing, IIT > (BHU): > > Hint 1) fib n = fib (n - 1) + fib (n - 2), with proper base cases > > > oke, so use recursion. No problem. > > Hint 2) use mapM_ to print a list of pairs, where the list is created by > zipping [1..] with the list of fibonacci numbers > > > mapM_ is not explained in the first 5 chapters of Craft of functional > programming, > > Can not both or one of the two be done with list comprehension because all > former exercises uses list comprehension > > Roelof > > > On 11 November 2015 at 18:29, Roelof Wobben wrote: > >> Hello, >> >> I have this exercise : >> >> Define a function >> fibTable :: Integer -> String >> which produces a table of Fibonacci numbers. For instance, the effect of >> putStr >> (fibTable 6) should be >> n fib n >> 0 0 >> 1 1 >> 2 1 >> 3 2 >> 4 3 >> 5 5 >> 6 8 >> >> >> >> 1) Can somone give me any pointers how to calculate the fibb numbers with >> list comprehension. >> I know that the fib numbers are (n -1) + n >> >> 2) Can someone give me any pointers how to write the outcome of every run >> >> Roelof >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > > > -- > Regards > > Sumit Sahrawat > > > _______________________________________________ > Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > Geen virus gevonden in dit bericht. > Gecontroleerd door AVG - www.avg.com > Versie: 2015.0.6176 / Virusdatabase: 4460/10979 - datum van uitgifte: > 11/11/15 > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From dennis.raddle at gmail.com Wed Nov 11 21:12:11 2015 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Wed, 11 Nov 2015 13:12:11 -0800 Subject: [Haskell-beginners] figured out use for join! Message-ID: I'm starting to get the hang of certain aspects of typeclasses, particularly with Maybe and list types. For instance I needed to write a function as follows: Ord k => k -> Map k [a] -> Maybe a which evaluates to "Nothing" if there is no such key in the map, or Just the first element of [a] if there is such a key, or Nothing if there is such a key but [a] is null. So I could write import qualified Data.Map as M import Control.Monad import Data.Maybe f k m = case M.lookup k m of Nothing -> Nothing Just xs -> listToMaybe xs But the case "Nothing -> Nothing" is suspicious... seems like that's always a clue some typeclass could simplify it. Eventually I figured out f k = join . fmap listToMaybe . M.lookup k -------------- next part -------------- An HTML attachment was scrubbed... URL: From raabe at froglogic.com Wed Nov 11 22:01:29 2015 From: raabe at froglogic.com (Frerich Raabe) Date: Wed, 11 Nov 2015 23:01:29 +0100 Subject: [Haskell-beginners] figured out use for join! In-Reply-To: References: Message-ID: <45e8d25234e33e926389e1fcf02f1be7@roundcube.froglogic.com> On 2015-11-11 22:12, Dennis Raddle wrote: > f k m = case M.lookup k m of > Nothing -> Nothing > Just xs -> listToMaybe xs > > But the case "Nothing -> Nothing" is suspicious... seems like that's always > a clue some typeclass could simplify it. Eventually I figured out > > f k = join . fmap listToMaybe . M.lookup k The 'Nothing -> Nothing' thing may also be a good hint that using the Maybe monad would be useful. Your function can also be defined as f k m = M.lookup k m >>= listToMaybe -- Frerich Raabe - raabe at froglogic.com www.froglogic.com - Multi-Platform GUI Testing From marcin.jan.mrotek at gmail.com Thu Nov 12 09:17:09 2015 From: marcin.jan.mrotek at gmail.com (Marcin Mrotek) Date: Thu, 12 Nov 2015 10:17:09 +0100 Subject: [Haskell-beginners] figured out use for join! In-Reply-To: <45e8d25234e33e926389e1fcf02f1be7@roundcube.froglogic.com> References: <45e8d25234e33e926389e1fcf02f1be7@roundcube.froglogic.com> Message-ID: Hello, > using the Maybe monad would be useful. But he already is? Anyway, `(x >>= f) == join (fmap f x)` Best regards, Marcin Mrotek -------------- next part -------------- An HTML attachment was scrubbed... URL: From raabe at froglogic.com Thu Nov 12 09:38:22 2015 From: raabe at froglogic.com (Frerich Raabe) Date: Thu, 12 Nov 2015 10:38:22 +0100 Subject: [Haskell-beginners] figured out use for join! In-Reply-To: References: <45e8d25234e33e926389e1fcf02f1be7@roundcube.froglogic.com> Message-ID: <1deec0ed7bcdbddb0c43173dcf43d7c8@roundcube.froglogic.com> On 2015-11-12 10:17, Marcin Mrotek wrote: >> using the Maybe monad would be useful. > > But he already is? Yes, of course, sorry for the imprecision. I meant to write 'using bind as defined for the Maybe monad'. -- Frerich Raabe - raabe at froglogic.com www.froglogic.com - Multi-Platform GUI Testing From dennis.raddle at gmail.com Thu Nov 12 11:45:24 2015 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Thu, 12 Nov 2015 03:45:24 -0800 Subject: [Haskell-beginners] question about list processing Message-ID: What would be an elegant way of writing this computeHead :: (a -> [b]) -> [a] -> [b] Where when [a] is null, it returns a null list, but when [a] contains one or more elements, it applies the given function to the head of a and returns that? Is there some existing typeclass operator that facilitates this? You can write computeHead _ [] = [] computeHead f (x:_) = f x But that first line seems suspicious to me... it makes me think about how in the list Monad, an empty list falls through. But I can't quite make it work. -------------- next part -------------- An HTML attachment was scrubbed... URL: From alt.mcarter at gmail.com Thu Nov 12 12:41:18 2015 From: alt.mcarter at gmail.com (Mark Carter) Date: Thu, 12 Nov 2015 12:41:18 +0000 Subject: [Haskell-beginners] OrdList implementation Message-ID: <564488EE.8000108@gmail.com> I am trying to implement "OrdList", which is a list that is guaranteed to be ordered. Here's my implementation so far: module OrdList (empty, fromList, insert, toList, OrdList(OrdList)) where import Data.List as L (span) data OrdList a = OrdList [a] deriving (Show) empty :: OrdList a empty = OrdList [] insert :: (Ord a) => a -> OrdList a -> OrdList a insert x ol = let -- OrdList xs = ol (before, after) = L.span (\el -> el <= x) $ toList xs in OrdList $ before ++ [x] ++ after fromList :: Ord a => [a] -> OrdList a fromList xs = if null xs then empty else insert (head xs) (fromList $ tail xs) toList :: OrdList t -> [t] toList xs = let OrdList xs' = xs in xs' It "works", but no doubt there's plenty to dislike about it. Some specific questions I have in mind: 1. Should OrdList be best implemented as a class, data, or newtype? If so, what changes need to be made? 2. How comes I can't refer to OrdList as a data type? This is a problem because I can't say that I want the type of something to be OrdList Int, for example. From martin at vlkk.cz Thu Nov 12 13:22:08 2015 From: martin at vlkk.cz (Martin Vlk) Date: Thu, 12 Nov 2015 13:22:08 +0000 Subject: [Haskell-beginners] question about list processing In-Reply-To: References: Message-ID: <56449280.8070400@vlkk.cz> How about: computeHead f = take 1 . fmap f Martin Dennis Raddle: > What would be an elegant way of writing this > > computeHead :: (a -> [b]) -> [a] -> [b] > > Where when [a] is null, it returns a null list, but when [a] contains one > or more elements, it applies the given function to the head of a and > returns that? Is there some existing typeclass operator that facilitates > this? > > You can write > > computeHead _ [] = [] > computeHead f (x:_) = f x > > But that first line seems suspicious to me... it makes me think about how > in the list Monad, an empty list falls through. But I can't quite make it > work. > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From martin at vlkk.cz Thu Nov 12 13:26:03 2015 From: martin at vlkk.cz (Martin Vlk) Date: Thu, 12 Nov 2015 13:26:03 +0000 Subject: [Haskell-beginners] question about list processing In-Reply-To: <56449280.8070400@vlkk.cz> References: <56449280.8070400@vlkk.cz> Message-ID: <5644936B.4040808@vlkk.cz> Oh, and a little background. fmap comes from the Functor typeclass, and lists have an instance of Functor so the empty list case is handled automatically. Then I used "take 1" to get the head in a safe way, e.g. defaulting to empty list if the output of fmap is empty. M. Martin Vlk: > How about: > > computeHead f = take 1 . fmap f > > Martin > > Dennis Raddle: >> What would be an elegant way of writing this >> >> computeHead :: (a -> [b]) -> [a] -> [b] >> >> Where when [a] is null, it returns a null list, but when [a] contains one >> or more elements, it applies the given function to the head of a and >> returns that? Is there some existing typeclass operator that facilitates >> this? >> >> You can write >> >> computeHead _ [] = [] >> computeHead f (x:_) = f x >> >> But that first line seems suspicious to me... it makes me think about how >> in the list Monad, an empty list falls through. But I can't quite make it >> work. >> >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > From dennis.raddle at gmail.com Thu Nov 12 13:33:22 2015 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Thu, 12 Nov 2015 05:33:22 -0800 Subject: [Haskell-beginners] question about list processing In-Reply-To: <5644936B.4040808@vlkk.cz> References: <56449280.8070400@vlkk.cz> <5644936B.4040808@vlkk.cz> Message-ID: Just after I posted that question, I started driving home, and on the drive I thought of your answer. I think I'm starting to ask the right questions when I'm programming in Haskell. Like redundancy and bloat is a sure sign that a more witty expression is available, and that I should consult the typeclasses. Second, I am not used to the implications of laziness, so it took me a while to hit on your solution because I keep thinking you have to map something over the whole list, and that if you only want to map it over the head, you are stuck. You can use 'map' also, instead of 'fmap', right? Is 'map' just 'fmap' for lists? D -------------- next part -------------- An HTML attachment was scrubbed... URL: From akaberto at gmail.com Thu Nov 12 13:41:11 2015 From: akaberto at gmail.com (akash g) Date: Thu, 12 Nov 2015 19:11:11 +0530 Subject: [Haskell-beginners] question about list processing In-Reply-To: References: <56449280.8070400@vlkk.cz> <5644936B.4040808@vlkk.cz> Message-ID: map is specialized for lists while fmap is for any functors. Its presence is historical. Prefer fmap over map. On Thu, Nov 12, 2015 at 7:03 PM, Dennis Raddle wrote: > Just after I posted that question, I started driving home, and on the > drive I thought of your answer. I think I'm starting to ask the right > questions when I'm programming in Haskell. Like redundancy and bloat is a > sure sign that a more witty expression is available, and that I should > consult the typeclasses. > > Second, I am not used to the implications of laziness, so it took me a > while to hit on your solution because I keep thinking you have to map > something over the whole list, and that if you only want to map it over the > head, you are stuck. > > You can use 'map' also, instead of 'fmap', right? Is 'map' just 'fmap' for > lists? > > D > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From akaberto at gmail.com Thu Nov 12 13:42:27 2015 From: akaberto at gmail.com (akash g) Date: Thu, 12 Nov 2015 19:12:27 +0530 Subject: [Haskell-beginners] question about list processing In-Reply-To: References: <56449280.8070400@vlkk.cz> <5644936B.4040808@vlkk.cz> Message-ID: http://stackoverflow.com/questions/7463500/why-do-we-have-map-fmap-and-liftm have very good answers on this. On Thu, Nov 12, 2015 at 7:11 PM, akash g wrote: > map is specialized for lists while fmap is for any functors. Its presence > is historical. Prefer fmap over map. > > On Thu, Nov 12, 2015 at 7:03 PM, Dennis Raddle > wrote: > >> Just after I posted that question, I started driving home, and on the >> drive I thought of your answer. I think I'm starting to ask the right >> questions when I'm programming in Haskell. Like redundancy and bloat is a >> sure sign that a more witty expression is available, and that I should >> consult the typeclasses. >> >> Second, I am not used to the implications of laziness, so it took me a >> while to hit on your solution because I keep thinking you have to map >> something over the whole list, and that if you only want to map it over the >> head, you are stuck. >> >> You can use 'map' also, instead of 'fmap', right? Is 'map' just 'fmap' >> for lists? >> >> D >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dennis.raddle at gmail.com Thu Nov 12 13:48:46 2015 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Thu, 12 Nov 2015 05:48:46 -0800 Subject: [Haskell-beginners] question about list processing In-Reply-To: References: <56449280.8070400@vlkk.cz> <5644936B.4040808@vlkk.cz> Message-ID: Speaking of lists and history, I noticed that a lot of library functions which were formerly defined over lists (when I first looked at Haskell six years ago) are now defined on Traversable, which makes it a lot harder for beginners to read the documentation. I have been playing with Haskell for five years, but not much, so I'm still a beginner. I just mentally substitute lists when I see Traversable. I only really use lists and Maybe, as far as instances of the typeclasses go. That's only two types, but a lot to learn! D On Thu, Nov 12, 2015 at 5:42 AM, akash g wrote: > > http://stackoverflow.com/questions/7463500/why-do-we-have-map-fmap-and-liftm > have very good answers on this. > > On Thu, Nov 12, 2015 at 7:11 PM, akash g wrote: > >> map is specialized for lists while fmap is for any functors. Its >> presence is historical. Prefer fmap over map. >> >> On Thu, Nov 12, 2015 at 7:03 PM, Dennis Raddle >> wrote: >> >>> Just after I posted that question, I started driving home, and on the >>> drive I thought of your answer. I think I'm starting to ask the right >>> questions when I'm programming in Haskell. Like redundancy and bloat is a >>> sure sign that a more witty expression is available, and that I should >>> consult the typeclasses. >>> >>> Second, I am not used to the implications of laziness, so it took me a >>> while to hit on your solution because I keep thinking you have to map >>> something over the whole list, and that if you only want to map it over the >>> head, you are stuck. >>> >>> You can use 'map' also, instead of 'fmap', right? Is 'map' just 'fmap' >>> for lists? >>> >>> D >>> >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From akaberto at gmail.com Thu Nov 12 13:58:44 2015 From: akaberto at gmail.com (akash g) Date: Thu, 12 Nov 2015 19:28:44 +0530 Subject: [Haskell-beginners] OrdList implementation In-Reply-To: <564488EE.8000108@gmail.com> References: <564488EE.8000108@gmail.com> Message-ID: Just a note on the data structure. Wouldn't a binary tree (a balanced one; red-black, avl etc) give a logarithmic time constant for insertion while a list will give you a worst case bound of n, n being the length of the list? https://hackage.haskell.org/package/containers-0.5.6.3/docs/Data-Map-Strict.html :: Data.Map uses a ordered balanced binary tree implementation for storing and retrieving key value pairs. Now, with that out of the way, For 1, you are defining OrdList a to be a new data type (or type with a data constructor). Just to make sure users of this package cannot construct ill-formed OrdList, you can hide the constructor and provide your custom constructor (like fromList and its ilk). For 2., I don't know what you mean but OrdList is a datatype or rather a type constructor which takes an additional concrete type to form a concrete type. In other words, OrdList is of the kind (*->*). Lookup kinds (wikibooks is good for this and so are http://dev.stephendiehl.com/hask/ and learn you a haskell for great good). On Thu, Nov 12, 2015 at 6:11 PM, Mark Carter wrote: > I am trying to implement "OrdList", which is a list that is guaranteed to > be ordered. Here's my implementation so far: > > module OrdList (empty, fromList, insert, toList, OrdList(OrdList)) where > import Data.List as L (span) > > data OrdList a = OrdList [a] deriving (Show) > > > empty :: OrdList a > empty = OrdList [] > > > insert :: (Ord a) => a -> OrdList a -> OrdList a > insert x ol = > let -- OrdList xs = ol > (before, after) = L.span (\el -> el <= x) $ toList xs > in > OrdList $ before ++ [x] ++ after > > fromList :: Ord a => [a] -> OrdList a > fromList xs = > if null xs then empty else insert (head xs) (fromList $ tail xs) > > toList :: OrdList t -> [t] > toList xs = > let OrdList xs' = xs in xs' > > > > It "works", but no doubt there's plenty to dislike about it. Some specific > questions I have in mind: > 1. Should OrdList be best implemented as a class, data, or newtype? If so, > what changes need to be made? > 2. How comes I can't refer to OrdList as a data type? This is a problem > because I can't say that I want the type of something to be OrdList Int, > for example. > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From akaberto at gmail.com Thu Nov 12 14:27:41 2015 From: akaberto at gmail.com (akash g) Date: Thu, 12 Nov 2015 19:57:41 +0530 Subject: [Haskell-beginners] question about list processing In-Reply-To: References: <56449280.8070400@vlkk.cz> <5644936B.4040808@vlkk.cz> Message-ID: I think these changes came with GHC 7.10. I also completely agree that this is difficult for beginners. They should've had a beginner's Prelude or something :) On Thu, Nov 12, 2015 at 7:18 PM, Dennis Raddle wrote: > Speaking of lists and history, I noticed that a lot of library functions > which were formerly defined over lists (when I first looked at Haskell six > years ago) are now defined on Traversable, which makes it a lot harder for > beginners to read the documentation. I have been playing with Haskell for > five years, but not much, so I'm still a beginner. I just mentally > substitute lists when I see Traversable. > > I only really use lists and Maybe, as far as instances of the typeclasses > go. That's only two types, but a lot to learn! > > D > > > > > On Thu, Nov 12, 2015 at 5:42 AM, akash g wrote: > >> >> http://stackoverflow.com/questions/7463500/why-do-we-have-map-fmap-and-liftm >> have very good answers on this. >> >> On Thu, Nov 12, 2015 at 7:11 PM, akash g wrote: >> >>> map is specialized for lists while fmap is for any functors. Its >>> presence is historical. Prefer fmap over map. >>> >>> On Thu, Nov 12, 2015 at 7:03 PM, Dennis Raddle >>> wrote: >>> >>>> Just after I posted that question, I started driving home, and on the >>>> drive I thought of your answer. I think I'm starting to ask the right >>>> questions when I'm programming in Haskell. Like redundancy and bloat is a >>>> sure sign that a more witty expression is available, and that I should >>>> consult the typeclasses. >>>> >>>> Second, I am not used to the implications of laziness, so it took me a >>>> while to hit on your solution because I keep thinking you have to map >>>> something over the whole list, and that if you only want to map it over the >>>> head, you are stuck. >>>> >>>> You can use 'map' also, instead of 'fmap', right? Is 'map' just 'fmap' >>>> for lists? >>>> >>>> D >>>> >>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>>> >>> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From akaberto at gmail.com Thu Nov 12 14:31:26 2015 From: akaberto at gmail.com (akash g) Date: Thu, 12 Nov 2015 20:01:26 +0530 Subject: [Haskell-beginners] question about list processing In-Reply-To: References: <56449280.8070400@vlkk.cz> <5644936B.4040808@vlkk.cz> Message-ID: There has been discussion on the changes to the Prelude. Just found this ( https://wiki.haskell.org/Foldable_Traversable_In_Prelude). On Thu, Nov 12, 2015 at 7:57 PM, akash g wrote: > I think these changes came with GHC 7.10. I also completely agree that > this is difficult for beginners. They should've had a beginner's Prelude > or something :) > > > > On Thu, Nov 12, 2015 at 7:18 PM, Dennis Raddle > wrote: > >> Speaking of lists and history, I noticed that a lot of library functions >> which were formerly defined over lists (when I first looked at Haskell six >> years ago) are now defined on Traversable, which makes it a lot harder for >> beginners to read the documentation. I have been playing with Haskell for >> five years, but not much, so I'm still a beginner. I just mentally >> substitute lists when I see Traversable. >> >> I only really use lists and Maybe, as far as instances of the typeclasses >> go. That's only two types, but a lot to learn! >> >> D >> >> >> >> >> On Thu, Nov 12, 2015 at 5:42 AM, akash g wrote: >> >>> >>> http://stackoverflow.com/questions/7463500/why-do-we-have-map-fmap-and-liftm >>> have very good answers on this. >>> >>> On Thu, Nov 12, 2015 at 7:11 PM, akash g wrote: >>> >>>> map is specialized for lists while fmap is for any functors. Its >>>> presence is historical. Prefer fmap over map. >>>> >>>> On Thu, Nov 12, 2015 at 7:03 PM, Dennis Raddle >>> > wrote: >>>> >>>>> Just after I posted that question, I started driving home, and on the >>>>> drive I thought of your answer. I think I'm starting to ask the right >>>>> questions when I'm programming in Haskell. Like redundancy and bloat is a >>>>> sure sign that a more witty expression is available, and that I should >>>>> consult the typeclasses. >>>>> >>>>> Second, I am not used to the implications of laziness, so it took me a >>>>> while to hit on your solution because I keep thinking you have to map >>>>> something over the whole list, and that if you only want to map it over the >>>>> head, you are stuck. >>>>> >>>>> You can use 'map' also, instead of 'fmap', right? Is 'map' just 'fmap' >>>>> for lists? >>>>> >>>>> D >>>>> >>>>> >>>>> _______________________________________________ >>>>> Beginners mailing list >>>>> Beginners at haskell.org >>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>> >>>>> >>>> >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Thu Nov 12 14:32:29 2015 From: toad3k at gmail.com (David McBride) Date: Thu, 12 Nov 2015 09:32:29 -0500 Subject: [Haskell-beginners] question about list processing In-Reply-To: References: <56449280.8070400@vlkk.cz> <5644936B.4040808@vlkk.cz> Message-ID: There was some real controversy over this change. People were strongly opposed to the change for exactly the reason you gave (among others), that it is hard for beginners. However, there was enough momentum that it went through, and now things like fmap and length work on a wide variety of data types. You can google ftp haskell controversy for more info. On Thu, Nov 12, 2015 at 8:48 AM, Dennis Raddle wrote: > Speaking of lists and history, I noticed that a lot of library functions > which were formerly defined over lists (when I first looked at Haskell six > years ago) are now defined on Traversable, which makes it a lot harder for > beginners to read the documentation. I have been playing with Haskell for > five years, but not much, so I'm still a beginner. I just mentally > substitute lists when I see Traversable. > > I only really use lists and Maybe, as far as instances of the typeclasses > go. That's only two types, but a lot to learn! > > D > > > > > On Thu, Nov 12, 2015 at 5:42 AM, akash g wrote: > >> >> http://stackoverflow.com/questions/7463500/why-do-we-have-map-fmap-and-liftm >> have very good answers on this. >> >> On Thu, Nov 12, 2015 at 7:11 PM, akash g wrote: >> >>> map is specialized for lists while fmap is for any functors. Its >>> presence is historical. Prefer fmap over map. >>> >>> On Thu, Nov 12, 2015 at 7:03 PM, Dennis Raddle >>> wrote: >>> >>>> Just after I posted that question, I started driving home, and on the >>>> drive I thought of your answer. I think I'm starting to ask the right >>>> questions when I'm programming in Haskell. Like redundancy and bloat is a >>>> sure sign that a more witty expression is available, and that I should >>>> consult the typeclasses. >>>> >>>> Second, I am not used to the implications of laziness, so it took me a >>>> while to hit on your solution because I keep thinking you have to map >>>> something over the whole list, and that if you only want to map it over the >>>> head, you are stuck. >>>> >>>> You can use 'map' also, instead of 'fmap', right? Is 'map' just 'fmap' >>>> for lists? >>>> >>>> D >>>> >>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>>> >>> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dennis.raddle at gmail.com Thu Nov 12 14:58:25 2015 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Thu, 12 Nov 2015 06:58:25 -0800 Subject: [Haskell-beginners] question about list processing In-Reply-To: <56449280.8070400@vlkk.cz> References: <56449280.8070400@vlkk.cz> Message-ID: Oh I needed join. computeHead :: (a -> [b]) -> [a] -> [b] computeHead f = join . take 1 . fmap f That's because f :: a -> [b] not f: a -> b On Thu, Nov 12, 2015 at 5:22 AM, Martin Vlk wrote: > How about: > > computeHead f = take 1 . fmap f > > Martin > > Dennis Raddle: > > What would be an elegant way of writing this > > > > computeHead :: (a -> [b]) -> [a] -> [b] > > > > Where when [a] is null, it returns a null list, but when [a] contains one > > or more elements, it applies the given function to the head of a and > > returns that? Is there some existing typeclass operator that facilitates > > this? > > > > You can write > > > > computeHead _ [] = [] > > computeHead f (x:_) = f x > > > > But that first line seems suspicious to me... it makes me think about how > > in the list Monad, an empty list falls through. But I can't quite make it > > work. > > > > > > > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin.drautzburg at web.de Thu Nov 12 15:52:06 2015 From: martin.drautzburg at web.de (martin) Date: Thu, 12 Nov 2015 16:52:06 +0100 Subject: [Haskell-beginners] Why this order of parameters Message-ID: <5644B5A6.70802@web.de> Hello all, there are two functions, where the order of parameters confuses me. Ons is runState :: State s a -> s -> (a, s) I understand that in the constructor s has to be first, so we can turn (State s) into a monad. But why doesn't s come first in the result too, as in runState :: State s a -> s -> (s, a) The other example is foldl, foldr foldl :: (a -> b -> a) -> a -> [b] -> a foldr :: (a -> b -> b) -> b -> [a] -> b For once the list is a list of as in foldl, but a list of as in foldr. Now that can be fixed with renaming the type parameters foldr :: (b -> a -> a) -> a -> [b] -> a this is the exact same thing and resembles more the type of foldl. But still the function argument has its parameters flipped. foldl's function takes the list element as second parameter and foldr's takes it as first parameter. Why is that so? From ahammel87 at gmail.com Thu Nov 12 16:20:28 2015 From: ahammel87 at gmail.com (Alex Hammel) Date: Thu, 12 Nov 2015 16:20:28 +0000 Subject: [Haskell-beginners] question about list processing In-Reply-To: References: <56449280.8070400@vlkk.cz> Message-ID: With the join it's the same thing as: computeHead :: (a -> [b]) -> [a] -> [b] computeHead f xs = take 1 xs >>= f On Thu, 12 Nov 2015 at 06:58 Dennis Raddle wrote: > Oh I needed join. > > computeHead :: (a -> [b]) -> [a] -> [b] > computeHead f = join . take 1 . fmap f > > That's because > > f :: a -> [b] > > not > > f: a -> b > > > On Thu, Nov 12, 2015 at 5:22 AM, Martin Vlk wrote: > >> How about: >> >> computeHead f = take 1 . fmap f >> >> Martin >> >> Dennis Raddle: >> > What would be an elegant way of writing this >> > >> > computeHead :: (a -> [b]) -> [a] -> [b] >> > >> > Where when [a] is null, it returns a null list, but when [a] contains >> one >> > or more elements, it applies the given function to the head of a and >> > returns that? Is there some existing typeclass operator that facilitates >> > this? >> > >> > You can write >> > >> > computeHead _ [] = [] >> > computeHead f (x:_) = f x >> > >> > But that first line seems suspicious to me... it makes me think about >> how >> > in the list Monad, an empty list falls through. But I can't quite make >> it >> > work. >> > >> > >> > >> > _______________________________________________ >> > Beginners mailing list >> > Beginners at haskell.org >> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjakway at nyu.edu Thu Nov 12 16:34:58 2015 From: tjakway at nyu.edu (Thomas Jakway) Date: Thu, 12 Nov 2015 11:34:58 -0500 Subject: [Haskell-beginners] My First Haskell Project--Please give feedback! Message-ID: <5644BFB2.3020304@nyu.edu> Hi everyone! I'm trying to write a blackjack simulator and would really appreciate advice on the code. I wrote about lots of specific things in an /r/haskell post: https://www.reddit.com/r/haskell/comments/3sjs0y/my_first_haskell_projectplease_give_feedback/ And the code is here: https://github.com/tjakway/blackjack-simulator/blob/master/src/Cards.hs (sorry if it's annoying to have to follow a link, thought it'd be better than just copy + pasting a huge blob here) Thanks in advance! From martin at vlkk.cz Thu Nov 12 17:00:24 2015 From: martin at vlkk.cz (Martin Vlk) Date: Thu, 12 Nov 2015 17:00:24 +0000 Subject: [Haskell-beginners] Why this order of parameters In-Reply-To: <5644B5A6.70802@web.de> References: <5644B5A6.70802@web.de> Message-ID: <5644C5A8.3090706@vlkk.cz> Hi, my first intuition about this is that in data constructor it technically doesn't matter, but you could argue that "a" represents the actual result of the function so it comes first. Second comes the state, which is the side thing, hence the secondary/less important position. As for the order of type constructor parameters you are right - state is part of the structure that Monoid, Functor, Applicative, Monad and the like use. Martin martin: > runState :: State s a -> s -> (a, s) > > I understand that in the constructor s has to be first, so we can turn (State s) into a monad. But why doesn't s come > first in the result too, as in > > runState :: State s a -> s -> (s, a) From objitsu at gmail.com Thu Nov 12 17:32:25 2015 From: objitsu at gmail.com (emacstheviking) Date: Thu, 12 Nov 2015 17:32:25 +0000 Subject: [Haskell-beginners] My First Haskell Project--Please give feedback! In-Reply-To: <5644BFB2.3020304@nyu.edu> References: <5644BFB2.3020304@nyu.edu> Message-ID: "The error messages are worse than gcc barfing on C++ templates" that had me laughing all the way to the kettle! I know what you mean! I will have a look myself sometime... On 12 November 2015 at 16:34, Thomas Jakway wrote: > Hi everyone! I'm trying to write a blackjack simulator and would really > appreciate advice on the code. > > I wrote about lots of specific things in an /r/haskell post: > > > https://www.reddit.com/r/haskell/comments/3sjs0y/my_first_haskell_projectplease_give_feedback/ > > And the code is here: > https://github.com/tjakway/blackjack-simulator/blob/master/src/Cards.hs > > (sorry if it's annoying to have to follow a link, thought it'd be better > than just copy + pasting a huge blob here) > > Thanks in advance! > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From i.caught.air at gmail.com Thu Nov 12 17:34:43 2015 From: i.caught.air at gmail.com (Alex Belanger) Date: Thu, 12 Nov 2015 12:34:43 -0500 Subject: [Haskell-beginners] Why this order of parameters In-Reply-To: <5644C5A8.3090706@vlkk.cz> References: <5644B5A6.70802@web.de> <5644C5A8.3090706@vlkk.cz> Message-ID: foldr :: (a -> b -> b) -> b -> [a] -> b foldr :: (b -> a -> a) -> a -> [b] -> a are exactly the same types; simply inverted names for the type variables. I don't clearly see any benefit. Alex. On Nov 12, 2015 12:00 PM, "Martin Vlk" wrote: > Hi, my first intuition about this is that in data constructor it > technically doesn't matter, but you could argue that "a" represents the > actual result of the function so it comes first. > Second comes the state, which is the side thing, hence the > secondary/less important position. > > As for the order of type constructor parameters you are right - state is > part of the structure that Monoid, Functor, Applicative, Monad and the > like use. > > Martin > > martin: > > runState :: State s a -> s -> (a, s) > > > > I understand that in the constructor s has to be first, so we can turn > (State s) into a monad. But why doesn't s come > > first in the result too, as in > > > > runState :: State s a -> s -> (s, a) > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Thu Nov 12 17:49:11 2015 From: toad3k at gmail.com (David McBride) Date: Thu, 12 Nov 2015 12:49:11 -0500 Subject: [Haskell-beginners] Why this order of parameters In-Reply-To: References: <5644B5A6.70802@web.de> <5644C5A8.3090706@vlkk.cz> Message-ID: He means why is the first argument a -> b -> b in one function but b -> a -> b in the other. And I have no answer for that. I admit to having been caught by that in the past. You can't just replace one with the other in code, you have to do a flip on the operator. On Thu, Nov 12, 2015 at 12:34 PM, Alex Belanger wrote: > foldr :: (a -> b -> b) -> b -> [a] -> b > foldr :: (b -> a -> a) -> a -> [b] -> a > > are exactly the same types; simply inverted names for the type variables. > > I don't clearly see any benefit. > > Alex. > On Nov 12, 2015 12:00 PM, "Martin Vlk" wrote: > >> Hi, my first intuition about this is that in data constructor it >> technically doesn't matter, but you could argue that "a" represents the >> actual result of the function so it comes first. >> Second comes the state, which is the side thing, hence the >> secondary/less important position. >> >> As for the order of type constructor parameters you are right - state is >> part of the structure that Monoid, Functor, Applicative, Monad and the >> like use. >> >> Martin >> >> martin: >> > runState :: State s a -> s -> (a, s) >> > >> > I understand that in the constructor s has to be first, so we can turn >> (State s) into a monad. But why doesn't s come >> > first in the result too, as in >> > >> > runState :: State s a -> s -> (s, a) >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin at vlkk.cz Thu Nov 12 17:49:20 2015 From: martin at vlkk.cz (Martin Vlk) Date: Thu, 12 Nov 2015 17:49:20 +0000 Subject: [Haskell-beginners] Why this order of parameters In-Reply-To: <5644B5A6.70802@web.de> References: <5644B5A6.70802@web.de> Message-ID: <5644D120.4020404@vlkk.cz> I think again this technically doesn't matter... I'm curious if this could be for the sake of making the types of the two functions (foldr/foldl) different? E.g. so that you can tell from the type what function it is. (I'm a Haskell beginner myself so would be curious to hear an expert's voice on this!) Martin martin: > foldl :: (a -> b -> a) -> a -> [b] -> a > foldr :: (a -> b -> b) -> b -> [a] -> b > > For once the list is a list of as in foldl, but a list of as in foldr. Now that can be fixed with renaming the type > parameters > > foldr :: (b -> a -> a) -> a -> [b] -> a > > this is the exact same thing and resembles more the type of foldl. But still the function argument has its parameters > flipped. foldl's function takes the list element as second parameter and foldr's takes it as first parameter. > > Why is that so? From hanche at math.ntnu.no Thu Nov 12 20:45:37 2015 From: hanche at math.ntnu.no (Harald Hanche-Olsen) Date: Thu, 12 Nov 2015 20:45:37 +0000 Subject: [Haskell-beginners] Why this order of parameters In-Reply-To: <5644D120.4020404@vlkk.cz> References: <5644B5A6.70802@web.de> <5644D120.4020404@vlkk.cz> Message-ID: Hmmm, I seem to have missed part of this conversation, but I?ll toss in my two cents anyhow: Consider the identities foldl (?) s [x,y,z] == ((s?x)?y)?z foldr (?) s [x,y,z] == x?(y?(z?s)) and I think it should be clear that the type of (?) must be a?b?a in the former and b?a?a in the latter. Either of these identities would look rather odd when written in operator notation if (?) were flipped! ? Harald -----Original Message----- From:?Martin Vlk Date:?12 November 2015 at 18:49:35 > I think again this technically doesn't matter... > > I'm curious if this could be for the sake of making the types of the two > functions (foldr/foldl) different? E.g. so that you can tell from the > type what function it is. > > (I'm a Haskell beginner myself so would be curious to hear an expert's > voice on this!) > > Martin > > martin: > > foldl :: (a -> b -> a) -> a -> [b] -> a > > foldr :: (a -> b -> b) -> b -> [a] -> b > > > > For once the list is a list of as in foldl, but a list of as in foldr. Now that can be fixed > with renaming the type > > parameters > > > > foldr :: (b -> a -> a) -> a -> [b] -> a > > > > this is the exact same thing and resembles more the type of foldl. But still the function > argument has its parameters > > flipped. foldl's function takes the list element as second parameter and foldr's takes > it as first parameter. > > > > Why is that so? > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Harald Hanche-Olsen F?rsteamanuensis Institutt for matematiske fag Norges teknisk-naturvitenskapelige universitet 7491 Trondheim http://www.math.ntnu.no/~hanche/ From dennis.raddle at gmail.com Thu Nov 12 21:00:04 2015 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Thu, 12 Nov 2015 13:00:04 -0800 Subject: [Haskell-beginners] question about list processing In-Reply-To: References: <56449280.8070400@vlkk.cz> <5644936B.4040808@vlkk.cz> Message-ID: On Thu, Nov 12, 2015 at 6:32 AM, David McBride wrote: > There was some real controversy over this change. People were strongly > opposed to the change for exactly the reason you gave (among others), that > it is hard for beginners. However, there was enough momentum that it went > through, and now things like fmap and length work on a wide variety of data > types. You can google ftp haskell controversy for more info. > > Thanks, David. As far as instances of Functor, Applicative, and Monad, so far I've mostly used lists and Maybe. I've never taken specific advantage of Traversable. Could you suggest a new type for me to explore? I mean something that could have instances in any of the above classes, one or all. I only use Haskell for an occasional hobby project so despite having started five years ago, I consider myself a beginner. My project involves playing music by transforming a musical score into MIDI commands and sending them to a software synthesizer. As far as library types, I mostly use Map, lists, and Maybe. These are all I have needed to look for patterns in lists or Maps of notes. But I'm sure I'm missing out on something. D -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Thu Nov 12 21:12:56 2015 From: toad3k at gmail.com (David McBride) Date: Thu, 12 Nov 2015 16:12:56 -0500 Subject: [Haskell-beginners] question about list processing In-Reply-To: References: <56449280.8070400@vlkk.cz> <5644936B.4040808@vlkk.cz> Message-ID: It is mostly just things like: Prelude.length (Data.Map.fromList [(1,"1"),(2,"2")]) Prelude.foldr (+) 0 (Data.Set.fromList [1,2,3,4,5]) Prelude.null Nothing Prelude.null (Just 2) Just watch out for some gotchas: minimum (1,2) On Thu, Nov 12, 2015 at 4:00 PM, Dennis Raddle wrote: > > > On Thu, Nov 12, 2015 at 6:32 AM, David McBride wrote: > >> There was some real controversy over this change. People were strongly >> opposed to the change for exactly the reason you gave (among others), that >> it is hard for beginners. However, there was enough momentum that it went >> through, and now things like fmap and length work on a wide variety of data >> types. You can google ftp haskell controversy for more info. >> >> > > > > Thanks, David. As far as instances of Functor, Applicative, and Monad, so > far I've mostly used lists and Maybe. I've never taken specific advantage > of Traversable. > > Could you suggest a new type for me to explore? I mean something that > could have instances in any of the above classes, one or all. > > I only use Haskell for an occasional hobby project so despite having > started five years ago, I consider myself a beginner. My project involves > playing music by transforming a musical score into MIDI commands and > sending them to a software synthesizer. As far as library types, I mostly > use Map, lists, and Maybe. These are all I have needed to look for patterns > in lists or Maps of notes. But I'm sure I'm missing out on something. > > D > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From strombrg at gmail.com Thu Nov 12 22:30:28 2015 From: strombrg at gmail.com (Dan Stromberg) Date: Thu, 12 Nov 2015 14:30:28 -0800 Subject: [Haskell-beginners] Best MD5 module? Message-ID: Hi again folks. What's the best module for doing an MD5 hash? More specifically, I want to hash the first few dozen K of a file, and then the entire file - to get two different hashes. I'm seeing at least 3 modules for it: https://hackage.haskhell.org/package/cryptohash-0.11.6/docs/Crypto-Hash-MD5.html https://hackage.haskell.org/package/pureMD5-2.1.2.1/docs/Data-Digest-Pure-MD5.html https://hackage.haskell.org/package/MissingH-1.3.0.1/docs/Data-Hash-MD5.html Which is best? Thanks! -- Dan Stromberg -------------- next part -------------- An HTML attachment was scrubbed... URL: From haskell at patrickmylund.com Thu Nov 12 22:37:11 2015 From: haskell at patrickmylund.com (Patrick Mylund Nielsen) Date: Thu, 12 Nov 2015 22:37:11 +0000 Subject: [Haskell-beginners] Best MD5 module? In-Reply-To: References: Message-ID: On Thu, Nov 12, 2015 at 5:30 PM Dan Stromberg wrote: > > What's the best module for doing an MD5 hash? > > More specifically, I want to hash the first few dozen K of a file, and > then the entire file - to get two different hashes. > I would use the one from cryptohash if you're looking for performance, however I must stress that using MD5 for anything "new" is almost certainly a bad idea. If you aren't doing this for compatibility reasons, you should use something else, like BLAKE2: https://blake2.net/ You might also be interested in https://hackage.haskell.org/package/saltine -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Fri Nov 13 01:08:41 2015 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Fri, 13 Nov 2015 08:08:41 +0700 Subject: [Haskell-beginners] Why this order of parameters In-Reply-To: <5644D120.4020404@vlkk.cz> References: <5644B5A6.70802@web.de> <5644D120.4020404@vlkk.cz> Message-ID: On Fri, Nov 13, 2015 at 12:49 AM, Martin Vlk wrote: > I'm curious if this could be for the sake of making the types of the two > functions (foldr/foldl) different? E.g. so that you can tell from the > type what function it is. > No, that would be foolish. One doesn't simply make the types different to distinguish them. Suppose the elements are already naturally foldable. Then foldr and foldl have the same type signature: foldl, foldr :: (a -> a -> a) -> a -> [a] -> a But sometimes they are only foldable qua another type. Call it r. If you work through Harald's reasoning, you'll arrive at: foldr :: (a -> r -> r) -> r -> [a] -> r foldl :: (r -> a -> r) -> r -> [a] -> r -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From strombrg at gmail.com Fri Nov 13 05:17:10 2015 From: strombrg at gmail.com (Dan Stromberg) Date: Thu, 12 Nov 2015 21:17:10 -0800 Subject: [Haskell-beginners] Best MD5 module? In-Reply-To: References: Message-ID: On Thu, Nov 12, 2015 at 2:37 PM, Patrick Mylund Nielsen < haskell at patrickmylund.com> wrote: > On Thu, Nov 12, 2015 at 5:30 PM Dan Stromberg wrote: > >> >> What's the best module for doing an MD5 hash? >> >> More specifically, I want to hash the first few dozen K of a file, and >> then the entire file - to get two different hashes. >> > > I would use the one from cryptohash if you're looking for performance, > however I must stress that using MD5 for anything "new" is almost certainly > a bad idea. If you aren't doing this for compatibility reasons, you should > use something else, like BLAKE2: https://blake2.net/ > > You might also be interested in > https://hackage.haskell.org/package/saltine > My use of MD5 is strictly non-cryptographic. It is in a limited sense for compatibility with other software - but it's more about doing the same algorithm in multiple languages for the sake of comparison. I'll look at cryptohash. Thanks. Dan Stromberg -------------- next part -------------- An HTML attachment was scrubbed... URL: From abhishekkmr18 at gmail.com Fri Nov 13 06:36:42 2015 From: abhishekkmr18 at gmail.com (Abhishek Kumar) Date: Fri, 13 Nov 2015 12:06:42 +0530 Subject: [Haskell-beginners] Query regarding an unusually behaving code Message-ID: Bellow is my code for returning a list of digits given an integer.I'm unable to find any bug in it but somehow it crashes any computer I run it on when I try to calculate digs 100.Please tell me bug in my code. let digs 0 =[0] let digs x = (digs (x `div` 10)) ++ [(x `rem` 10)] digs 100 Thanks Abhishek -------------- next part -------------- An HTML attachment was scrubbed... URL: From grzegorzmilka at gmail.com Fri Nov 13 06:43:52 2015 From: grzegorzmilka at gmail.com (Grzegorz Milka) Date: Fri, 13 Nov 2015 07:43:52 +0100 Subject: [Haskell-beginners] Query regarding an unusually behaving code In-Reply-To: References: Message-ID: <564586A8.7090609@gmail.com> The problem is that you define digs twice and the second definition overshadows the first one. This makes your recursion infinite. You should define all cases at once like: let digs 0 = [0]; digs x = (digs (x `div` 10)) ++ [(x `rem` 10)] Greg On 13.11.2015 07:36, Abhishek Kumar wrote: > Bellow is my code for returning a list of digits given an integer.I'm > unable to find any bug in it but somehow it crashes any computer I run it > on when I try to calculate digs 100.Please tell me bug in my code. > > let digs 0 =[0] > let digs x = (digs (x `div` 10)) ++ [(x `rem` 10)] > digs 100 > > Thanks > Abhishek > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From akaberto at gmail.com Fri Nov 13 06:47:33 2015 From: akaberto at gmail.com (akash g) Date: Fri, 13 Nov 2015 12:17:33 +0530 Subject: [Haskell-beginners] Query regarding an unusually behaving code In-Reply-To: References: Message-ID: This is because the second let redefines your first definition. Hence, you don't have a base case anymore. digs 0 =[] digs x = (digs (x `div` 10)) ++ [(x `rem` 10)] When I compile this with ghc though, it works fine. This is how ghci works, I'd presume. On Fri, Nov 13, 2015 at 12:06 PM, Abhishek Kumar wrote: > Bellow is my code for returning a list of digits given an integer.I'm > unable to find any bug in it but somehow it crashes any computer I run it > on when I try to calculate digs 100.Please tell me bug in my code. > > let digs 0 =[0] > let digs x = (digs (x `div` 10)) ++ [(x `rem` 10)] > digs 100 > > Thanks > Abhishek > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rein.henrichs at gmail.com Fri Nov 13 21:32:35 2015 From: rein.henrichs at gmail.com (Rein Henrichs) Date: Fri, 13 Nov 2015 13:32:35 -0800 Subject: [Haskell-beginners] is this not a better way ? data structure In-Reply-To: <563E739B.9080202@home.nl> (Roelof Wobben's message of "Sat, 7 Nov 2015 22:56:43 +0100") References: <563E739B.9080202@home.nl> Message-ID: As an aside, don't use ~Float~. Unless you have a specific reason to want a half-precision floating point type, you should use ~Double~. -------------- next part -------------- An HTML attachment was scrubbed... URL: From strombrg at gmail.com Sat Nov 14 01:41:45 2015 From: strombrg at gmail.com (Dan Stromberg) Date: Fri, 13 Nov 2015 17:41:45 -0800 Subject: [Haskell-beginners] Opaque (to me) compilation error Message-ID: In the following code: prefix_md5 :: String -> Data.ByteString.ByteString prefix_md5 filename = do let prefix_length = 1024 file <- System.IO.openBinaryFile filename System.IO.ReadMode :: (IO System.IO.Handle) data_read <- Data.ByteString.hGet file prefix_length :: (IO Data.ByteString.ByteString) _ <- System.IO.hClose file let hasher = Crypto.Hash.MD5.init :: Crypto.Hash.MD5.Ctx let hasher2 = Crypto.Hash.MD5.update hasher data_read :: Crypto.Hash.MD5.Ctx let digest = Crypto.Hash.MD5.finalize hasher2 :: Data.ByteString.ByteString return digest :: (IO Data.ByteString.ByteString) I get the error: Md5s.hs:13:5: Couldn't match type `IO Data.ByteString.ByteString' with `Data.ByteString.ByteString' Expected type: IO System.IO.Handle -> (System.IO.Handle -> IO Data.ByteString.ByteString) -> Data.ByteString.ByteString Actual type: IO System.IO.Handle -> (System.IO.Handle -> IO Data.ByteString.ByteString) -> IO Data.ByteString.ByteString In a stmt of a 'do' block: file <- System.IO.openBinaryFile filename System.IO.ReadMode :: IO System.IO.Handle How should I interpret that error to solve this kind of problem on my own in the future? I don't see where the line in question does anything with ByteString's! How might I correct this function to eliminate the error? Thanks! -- Dan Stromberg -------------- next part -------------- An HTML attachment was scrubbed... URL: From tanuki at gmail.com Sat Nov 14 02:24:24 2015 From: tanuki at gmail.com (Theodore Lief Gannon) Date: Fri, 13 Nov 2015 21:24:24 -0500 Subject: [Haskell-beginners] Opaque (to me) compilation error In-Reply-To: References: Message-ID: You're missing IO in the type declaration, which I believe means that do block is running in the Id monad -- by inference, Id ByteString. On Fri, Nov 13, 2015 at 8:41 PM, Dan Stromberg wrote: > > In the following code: > prefix_md5 :: String -> Data.ByteString.ByteString > prefix_md5 filename = do > let prefix_length = 1024 > file <- System.IO.openBinaryFile filename System.IO.ReadMode :: (IO > System.IO.Handle) > data_read <- Data.ByteString.hGet file prefix_length :: (IO > Data.ByteString.ByteString) > _ <- System.IO.hClose file > let hasher = Crypto.Hash.MD5.init :: Crypto.Hash.MD5.Ctx > let hasher2 = Crypto.Hash.MD5.update hasher data_read :: > Crypto.Hash.MD5.Ctx > let digest = Crypto.Hash.MD5.finalize hasher2 :: > Data.ByteString.ByteString > return digest :: (IO Data.ByteString.ByteString) > > I get the error: > Md5s.hs:13:5: > Couldn't match type `IO Data.ByteString.ByteString' > with `Data.ByteString.ByteString' > Expected type: IO System.IO.Handle > -> (System.IO.Handle -> IO Data.ByteString.ByteString) > -> Data.ByteString.ByteString > Actual type: IO System.IO.Handle > -> (System.IO.Handle -> IO Data.ByteString.ByteString) > -> IO Data.ByteString.ByteString > In a stmt of a 'do' block: > file <- System.IO.openBinaryFile filename System.IO.ReadMode :: > IO System.IO.Handle > > How should I interpret that error to solve this kind of problem on my own > in the future? I don't see where the line in question does anything with > ByteString's! > > How might I correct this function to eliminate the error? > > Thanks! > > -- > Dan Stromberg > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tanuki at gmail.com Sat Nov 14 02:30:25 2015 From: tanuki at gmail.com (Theodore Lief Gannon) Date: Fri, 13 Nov 2015 21:30:25 -0500 Subject: [Haskell-beginners] Opaque (to me) compilation error In-Reply-To: References: Message-ID: Note that the analysis in my previous message is based on a trick I saw a year ago and clearly don't properly remember or understand, because there is no "Id" monad and the *Identity* monad is apparently not in base (though you might still have it there, it's in both mtl and transformers). But the bit about your type signature still stands. I'm quite certain of that part. :) On Fri, Nov 13, 2015 at 9:24 PM, Theodore Lief Gannon wrote: > You're missing IO in the type declaration, which I believe means that do > block is running in the Id monad -- by inference, Id ByteString. > > On Fri, Nov 13, 2015 at 8:41 PM, Dan Stromberg wrote: > >> >> In the following code: >> prefix_md5 :: String -> Data.ByteString.ByteString >> prefix_md5 filename = do >> let prefix_length = 1024 >> file <- System.IO.openBinaryFile filename System.IO.ReadMode :: (IO >> System.IO.Handle) >> data_read <- Data.ByteString.hGet file prefix_length :: (IO >> Data.ByteString.ByteString) >> _ <- System.IO.hClose file >> let hasher = Crypto.Hash.MD5.init :: Crypto.Hash.MD5.Ctx >> let hasher2 = Crypto.Hash.MD5.update hasher data_read :: >> Crypto.Hash.MD5.Ctx >> let digest = Crypto.Hash.MD5.finalize hasher2 :: >> Data.ByteString.ByteString >> return digest :: (IO Data.ByteString.ByteString) >> >> I get the error: >> Md5s.hs:13:5: >> Couldn't match type `IO Data.ByteString.ByteString' >> with `Data.ByteString.ByteString' >> Expected type: IO System.IO.Handle >> -> (System.IO.Handle -> IO Data.ByteString.ByteString) >> -> Data.ByteString.ByteString >> Actual type: IO System.IO.Handle >> -> (System.IO.Handle -> IO Data.ByteString.ByteString) >> -> IO Data.ByteString.ByteString >> In a stmt of a 'do' block: >> file <- System.IO.openBinaryFile filename System.IO.ReadMode :: >> IO System.IO.Handle >> >> How should I interpret that error to solve this kind of problem on my own >> in the future? I don't see where the line in question does anything with >> ByteString's! >> >> How might I correct this function to eliminate the error? >> >> Thanks! >> >> -- >> Dan Stromberg >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Sat Nov 14 03:52:37 2015 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Sat, 14 Nov 2015 10:52:37 +0700 Subject: [Haskell-beginners] Opaque (to me) compilation error In-Reply-To: References: Message-ID: On Sat, Nov 14, 2015 at 9:24 AM, Theodore Lief Gannon wrote: > You're missing IO in the type declaration, which I believe means that do > block is running in the Id monad -- by inference, Id ByteString. There's no running in the Id monad. The compiler doesn't understand monads the way we'd like it to. It's all very syntactic, namely: 1. the compiler desugars the do block into an expression 2. it typechecks the expression: no special understanding of the monad typeclass involved 3. and if there are errors, it reports them What we're seeing is special handling for stage 3: reporting errors in a do-block. Sometimes it helps, sometimes it hinders. For instance, the derivation of this signature is confusing indeed: IO System.IO.Handle -> (System.IO.Handle -> IO Data.ByteString.ByteString) -> Data.ByteString.ByteString -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Sat Nov 14 09:44:24 2015 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Sat, 14 Nov 2015 16:44:24 +0700 Subject: [Haskell-beginners] Opaque (to me) compilation error In-Reply-To: References: Message-ID: On Sat, Nov 14, 2015 at 10:52 AM, Kim-Ee Yeoh wrote: > What we're seeing is special handling for stage 3: reporting errors in a > do-block. Sometimes it helps, sometimes it hinders. For instance, the > derivation of this signature is confusing indeed: > > IO System.IO.Handle > -> (System.IO.Handle -> IO Data.ByteString.ByteString) > -> Data.ByteString.ByteString > To elaborate, the error message comes from the compiler choking on the monadic bind (>>=) that reveals itself in the desugared code. The (>>=) results from desugaring file <- openBinaryFile filename ReadMode into openBinaryFile filename ReadMode >>= \file -> ... The compiler knows the type signature of (>>=), which wants to see IO Handle -> (Handle -> IO ByteString) -> IO ByteString But the signature of the top-level function insists on IO Handle -> (Handle -> IO ByteString) -> ByteString This is what's the compiler's trying to say. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From K.Bleijenberg at lijbrandt.nl Sat Nov 14 18:56:45 2015 From: K.Bleijenberg at lijbrandt.nl (Kees Bleijenberg) Date: Sat, 14 Nov 2015 19:56:45 +0100 Subject: [Haskell-beginners] Generate a list of all constructors Message-ID: <000601d11f0e$35456ac0$9fd04040$@lijbrandt.nl> In this piece of code data Color = RED | BLUE | YELLOW allColors :: [Color] allColors = [RED, BLUE, YELLOW] I have to remeber that if I add a Color, I have to add the color in allColors too. Is there no better way to add all possible colors in allColors? Kees -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Sat Nov 14 19:12:38 2015 From: fa-ml at ariis.it (Francesco Ariis) Date: Sat, 14 Nov 2015 20:12:38 +0100 Subject: [Haskell-beginners] Generate a list of all constructors In-Reply-To: <000601d11f0e$35456ac0$9fd04040$@lijbrandt.nl> References: <000601d11f0e$35456ac0$9fd04040$@lijbrandt.nl> Message-ID: <20151114191238.GA8443@casa.casa> On Sat, Nov 14, 2015 at 07:56:45PM +0100, Kees Bleijenberg wrote: > In this piece of code > > > > data Color = RED | BLUE | YELLOW > > > > allColors :: [Color] > > allColors = [RED, BLUE, YELLOW] > > > > I have to remeber that if I add a Color, I have to add the color in > allColors too. > > Is there no better way to add all possible colors in allColors? Yes, if you make Color instance of Enum. E.g.: data Color = RED | BLUE | YELLOW deriving (Show, Enum) allColors = enumFrom RED From martin at vlkk.cz Sat Nov 14 19:37:35 2015 From: martin at vlkk.cz (Martin Vlk) Date: Sat, 14 Nov 2015 19:37:35 +0000 Subject: [Haskell-beginners] Why this order of parameters In-Reply-To: References: <5644B5A6.70802@web.de> <5644D120.4020404@vlkk.cz> Message-ID: <56478D7F.2040605@vlkk.cz> Harald and Kim-Ee, thanks for your explanations. So in other words the order of parameters naturally follows from the corresponding equations and is not driven by technical need. A follow up question.. what do you mean by elements being "naturally foldable"? Is it that you could just cons them together without any transformation? Martin Kim-Ee Yeoh: > On Fri, Nov 13, 2015 at 12:49 AM, Martin Vlk wrote: > >> I'm curious if this could be for the sake of making the types of the two >> functions (foldr/foldl) different? E.g. so that you can tell from the >> type what function it is. >> > > No, that would be foolish. One doesn't simply make the types different to > distinguish them. > > Suppose the elements are already naturally foldable. Then foldr and foldl > have the same type signature: > > foldl, foldr :: (a -> a -> a) -> a -> [a] -> a > > But sometimes they are only foldable qua another type. Call it r. If you > work through Harald's reasoning, you'll arrive at: > > foldr :: (a -> r -> r) -> r -> [a] -> r > foldl :: (r -> a -> r) -> r -> [a] -> r > > -- Kim-Ee > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From amindfv at gmail.com Sat Nov 14 23:32:56 2015 From: amindfv at gmail.com (amindfv at gmail.com) Date: Sat, 14 Nov 2015 18:32:56 -0500 Subject: [Haskell-beginners] Generate a list of all constructors In-Reply-To: <20151114191238.GA8443@casa.casa> References: <000601d11f0e$35456ac0$9fd04040$@lijbrandt.nl> <20151114191238.GA8443@casa.casa> Message-ID: <187FD11B-8303-4E52-B648-01FED10435CD@gmail.com> The problem there is if you add a new color before "RED". I'd do: data Color = RED | BLUE | YELLOW deriving (Show, Enum, Bounded) allColors :: [Color] allColors = [minBound..maxBound] tom > El 14 nov 2015, a las 14:12, Francesco Ariis escribi?: > >> On Sat, Nov 14, 2015 at 07:56:45PM +0100, Kees Bleijenberg wrote: >> In this piece of code >> >> >> >> data Color = RED | BLUE | YELLOW >> >> >> >> allColors :: [Color] >> >> allColors = [RED, BLUE, YELLOW] >> >> >> >> I have to remeber that if I add a Color, I have to add the color in >> allColors too. >> >> Is there no better way to add all possible colors in allColors? > > Yes, if you make Color instance of Enum. E.g.: > > data Color = RED | BLUE | YELLOW deriving (Show, Enum) > allColors = enumFrom RED > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From math.simplex at gmail.com Sun Nov 15 02:29:21 2015 From: math.simplex at gmail.com (Graham Gill) Date: Sat, 14 Nov 2015 21:29:21 -0500 Subject: [Haskell-beginners] which Applicative instance? Message-ID: <5647EE01.5090702@gmail.com> I'm following the CIS194 lectures and exercises. In particular, in one of the Applicative lectures [0] we're asked to implement mapA and sequenceA, from the name and given type signature alone. I renamed them mapA' and sequenceA' to avoid name clashes, and defined: import Control.Applicative mapA' :: Applicative f => (a -> f b) -> ([a] -> f [b]) mapA' f = sequenceA' . map f sequenceA' :: Applicative f => [f a] -> f [a] sequenceA' = foldr (\fa fla -> (:) <$> fa <*> fla) (pure []) These implementations seem to be correct, though undoubtedly not the nicest. Now, I ask for a type in ghci: > :t mapA' pure [1..5] mapA' pure [1..5] :: (Enum b, Num b, Applicative f) => f [b] And so I try the following: > mapA' pure [1..5] :: [[Int]] [[1,2,3,4,5]] > take 5 . getZipList $ (mapA' pure [1..5] :: ZipList [Int]) [[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5]] > mapA' pure [1..5] :: Maybe [Int] Just [1,2,3,4,5] That makes sense. But I don't understand the following: > mapA' pure [1..5] [1,2,3,4,5] Which Applicative instance is being used here? The type test above says my expression should have type f [b], where f is an Applicative and b is a Num, but all I see is a result of type [b] when I compute mapA' pure [1..5]. What's going on? More simply > :t pure pure :: Applicative f => a -> f a > pure [1..5] [1,2,3,4,5] a must match a list of Nums, but then where did f go? Is ghci using some default instance? Actually, after I add the following lines to my source file: ggg = pure [1..5] hhh = mapA' pure [1..5] I get the errors: No instance for (Applicative f0) arising from a use of ?pure? No instance for (Applicative f1) arising from a use of ?mapA'? respectively. That makes sense to me. Graham [0] http://www.seas.upenn.edu/~cis194/fall14/spring13/lectures/11-applicative2.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From amindfv at gmail.com Sun Nov 15 02:35:01 2015 From: amindfv at gmail.com (amindfv at gmail.com) Date: Sat, 14 Nov 2015 21:35:01 -0500 Subject: [Haskell-beginners] Query regarding an unusually behaving code In-Reply-To: References: Message-ID: In ghci you want to make a multi-line expression: :{ let digs 0 =[0] digs x = (digs (x `div` 10)) ++ [(x `rem` 10)] :} (Note we don't put "let" on the second line) tom > El 13 nov 2015, a las 01:47, akash g escribi?: > > let digs 0 =[0] > let digs x = (digs (x `div` 10)) ++ [(x `rem` 10)] From ky3 at atamo.com Sun Nov 15 02:58:04 2015 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Sun, 15 Nov 2015 09:58:04 +0700 Subject: [Haskell-beginners] which Applicative instance? In-Reply-To: <5647EE01.5090702@gmail.com> References: <5647EE01.5090702@gmail.com> Message-ID: On Sun, Nov 15, 2015 at 9:29 AM, Graham Gill wrote: > More simply > > :t pure > pure :: Applicative f => a -> f a > > pure [1..5] > [1,2,3,4,5] > > a must match a list of Nums, but then where did f go? Is ghci using some > default instance? > Yes it is. The default instance is IO. It's a common gotcha, see https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/interactive-evaluation.html#actions-at-prompt and the example of how "return True" defaults to IO Bool. Might I compliment you on this: sequenceA' :: Applicative f => [f a] -> f [a] sequenceA' = foldr (\fa fla -> (:) <$> fa <*> fla) (pure []) There are strong arguments that this is the best way of writing sequenceA. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From tanuki at gmail.com Sun Nov 15 04:42:53 2015 From: tanuki at gmail.com (Theodore Lief Gannon) Date: Sat, 14 Nov 2015 23:42:53 -0500 Subject: [Haskell-beginners] Query regarding an unusually behaving code In-Reply-To: References: Message-ID: GHCi doesn't quite support everything you could put in a source file. To do what you want here, you need to use Haskell's alternative block syntax: :{ let { digs 0 = [0] ; digs x = (digs (x `div` 10)) ++ [(x `rem` 10)] } :} ...yep, curly braces and semicolons just like C-family. :) It's intended for machine-generated code, but works for this too. And in fact you actually don't need multi-line, this is legal: let { digs 0 = [0]; digs x = (digs (x `div` 10)) ++ [(x `rem` 10)] } On Sat, Nov 14, 2015 at 9:35 PM, wrote: > In ghci you want to make a multi-line expression: > > :{ > let digs 0 =[0] > digs x = (digs (x `div` 10)) ++ [(x `rem` 10)] > :} > > (Note we don't put "let" on the second line) > > tom > > > > El 13 nov 2015, a las 01:47, akash g escribi?: > > > > let digs 0 =[0] > > let digs x = (digs (x `div` 10)) ++ [(x `rem` 10)] > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tanuki at gmail.com Sun Nov 15 04:45:26 2015 From: tanuki at gmail.com (Theodore Lief Gannon) Date: Sat, 14 Nov 2015 23:45:26 -0500 Subject: [Haskell-beginners] Query regarding an unusually behaving code In-Reply-To: References: Message-ID: Gah, got here late and missed that this was a response, not the problem description. That's twice now I've put my foot in it. Stupid mailinglists, with no edit buttons... Well at least in both cases I've added SOMETHING useful. :) On Sat, Nov 14, 2015 at 11:42 PM, Theodore Lief Gannon wrote: > GHCi doesn't quite support everything you could put in a source file. To > do what you want here, you need to use Haskell's alternative block syntax: > > :{ > let { digs 0 = [0] > ; digs x = (digs (x `div` 10)) ++ [(x `rem` 10)] > } > :} > > ...yep, curly braces and semicolons just like C-family. :) It's intended > for machine-generated code, but works for this too. And in fact you > actually don't need multi-line, this is legal: > > let { digs 0 = [0]; digs x = (digs (x `div` 10)) ++ [(x `rem` 10)] } > > > On Sat, Nov 14, 2015 at 9:35 PM, wrote: > >> In ghci you want to make a multi-line expression: >> >> :{ >> let digs 0 =[0] >> digs x = (digs (x `div` 10)) ++ [(x `rem` 10)] >> :} >> >> (Note we don't put "let" on the second line) >> >> tom >> >> >> > El 13 nov 2015, a las 01:47, akash g escribi?: >> > >> > let digs 0 =[0] >> > let digs x = (digs (x `div` 10)) ++ [(x `rem` 10)] >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From math.simplex at gmail.com Sun Nov 15 05:35:17 2015 From: math.simplex at gmail.com (Graham Gill) Date: Sun, 15 Nov 2015 00:35:17 -0500 Subject: [Haskell-beginners] which Applicative instance? In-Reply-To: References: <5647EE01.5090702@gmail.com> Message-ID: <56481995.5070400@gmail.com> On 11/14/2015 9:58 PM, Kim-Ee Yeoh wrote: [...] > Yes it is. The default instance is IO. It's a common gotcha, see > > https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/interactive-evaluation.html#actions-at-prompt > > > and the example of how "return True" defaults to IO Bool. Thanks Kim-Ee, that makes it clear. > Might I compliment you on this: > > sequenceA' :: Applicative f => [f a] -> f [a] > sequenceA' = foldr (\fa fla -> (:) <$> fa <*> fla) (pure []) > > There are strong arguments that this is the best way of writing sequenceA. > > -- Kim-Ee Thanks, but it just seemed the most straightforward thing to do at my present level of understanding. Are there substantially different ways to define sequenceA? I'm interested to read the arguments if you can give a pointer to a post somewhere. Graham -------------- next part -------------- An HTML attachment was scrubbed... URL: From alt.mcarter at gmail.com Mon Nov 16 11:44:35 2015 From: alt.mcarter at gmail.com (Mark Carter) Date: Mon, 16 Nov 2015 11:44:35 +0000 Subject: [Haskell-beginners] Is there an idiom for this? Message-ID: <5649C1A3.1010901@gmail.com> Suppose I want to use an argument twice, as for example in the expression: (\x -> (pred1 x) and (pred2 x)) Is there a shorter way of doing this? From objitsu at gmail.com Mon Nov 16 11:53:28 2015 From: objitsu at gmail.com (emacstheviking) Date: Mon, 16 Nov 2015 11:53:28 +0000 Subject: [Haskell-beginners] Is there an idiom for this? In-Reply-To: <5649C1A3.1010901@gmail.com> References: <5649C1A3.1010901@gmail.com> Message-ID: I guess it depends on the final use cases... you could use currying to partially evaluate some stuff ready, locked and loaded as it were but the example you have given shows to distinct functions pres1 and pred2. I guess the short answer is "yes" but it depends on how you do it! :) Sean On 16 November 2015 at 11:44, Mark Carter wrote: > Suppose I want to use an argument twice, as for example in the expression: > (\x -> (pred1 x) and (pred2 x)) > > Is there a shorter way of doing this? > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From edwards.benj at gmail.com Mon Nov 16 12:07:11 2015 From: edwards.benj at gmail.com (Benjamin Edwards) Date: Mon, 16 Nov 2015 12:07:11 +0000 Subject: [Haskell-beginners] Is there an idiom for this? In-Reply-To: References: <5649C1A3.1010901@gmail.com> Message-ID: You can be cute and use the applicative instance on functions: (&&) <$> pred1 <*> pred2. I would recommend against such cuteness however and just write out the arguments. On Mon, 16 Nov 2015 at 11:54 emacstheviking wrote: > I guess it depends on the final use cases... you could use currying to > partially evaluate some stuff ready, locked and loaded as it were but the > example you have given shows to distinct functions pres1 and pred2. > > I guess the short answer is "yes" but it depends on how you do it! > > :) > Sean > > > On 16 November 2015 at 11:44, Mark Carter wrote: > >> Suppose I want to use an argument twice, as for example in the expression: >> (\x -> (pred1 x) and (pred2 x)) >> >> Is there a shorter way of doing this? >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From raabe at froglogic.com Mon Nov 16 12:10:44 2015 From: raabe at froglogic.com (Frerich Raabe) Date: Mon, 16 Nov 2015 13:10:44 +0100 Subject: [Haskell-beginners] =?utf-8?q?Is_there_an_idiom_for_this=3F?= In-Reply-To: <5649C1A3.1010901@gmail.com> References: <5649C1A3.1010901@gmail.com> Message-ID: <0a1589253e137f6af62659ac5f9941c4@roundcube.froglogic.com> On 2015-11-16 12:44, Mark Carter wrote: > Suppose I want to use an argument twice, as for example in the expression: > (\x -> (pred1 x) and (pred2 x)) > > Is there a shorter way of doing this? I suppose you meant to write '&&' instead of 'and'? You can write it in an applicative style as (&&) <$> pred1 <*> pred2 If you like, you can shorten that a bit using 'liftA2' as liftA2 (&&) pred1 pred2 but I personally tend to like the former version better. -- Frerich Raabe - raabe at froglogic.com www.froglogic.com - Multi-Platform GUI Testing From akaberto at gmail.com Mon Nov 16 14:08:04 2015 From: akaberto at gmail.com (akash g) Date: Mon, 16 Nov 2015 19:38:04 +0530 Subject: [Haskell-beginners] Is there an idiom for this? In-Reply-To: <0a1589253e137f6af62659ac5f9941c4@roundcube.froglogic.com> References: <5649C1A3.1010901@gmail.com> <0a1589253e137f6af62659ac5f9941c4@roundcube.froglogic.com> Message-ID: And here's the arrow implementation (pred1 &&& pred2) >>> uncurry (&&) You need Data.Tuple (for uncurry) and Data.Arrow. On Mon, Nov 16, 2015 at 5:40 PM, Frerich Raabe wrote: > On 2015-11-16 12:44, Mark Carter wrote: > >> Suppose I want to use an argument twice, as for example in the expression: >> (\x -> (pred1 x) and (pred2 x)) >> >> Is there a shorter way of doing this? >> > > I suppose you meant to write '&&' instead of 'and'? > > You can write it in an applicative style as > > (&&) <$> pred1 <*> pred2 > > If you like, you can shorten that a bit using 'liftA2' as > > liftA2 (&&) pred1 pred2 > > but I personally tend to like the former version better. > > -- > Frerich Raabe - raabe at froglogic.com > www.froglogic.com - Multi-Platform GUI Testing > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Mon Nov 16 20:40:16 2015 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Tue, 17 Nov 2015 03:40:16 +0700 Subject: [Haskell-beginners] Why this order of parameters In-Reply-To: <56478D7F.2040605@vlkk.cz> References: <5644B5A6.70802@web.de> <5644D120.4020404@vlkk.cz> <56478D7F.2040605@vlkk.cz> Message-ID: On Sun, Nov 15, 2015 at 2:37 AM, Martin Vlk wrote: > > A follow up question.. what do you mean by elements being "naturally > foldable"? Is it that you could just cons them together without any > transformation? > E.g. Numbers are naturally summable. Summing is a form of folding. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From traqueofziche at gmail.com Mon Nov 16 21:35:05 2015 From: traqueofziche at gmail.com (=?UTF-8?B?6bKN5Yev5paH?=) Date: Mon, 16 Nov 2015 13:35:05 -0800 Subject: [Haskell-beginners] Is there an idiom for this? Message-ID: I think i saw a relevant stackoverflow question before, but I can't find it. Anyways, the answer said something like: liftA2 (&&) pred1 pred2 which has the type a -> Bool, as desired. The reader applicative gives your input to both predicates and (&&) is applied to their results. Hope I remembered this correctly. On Nov 16, 2015 4:01 AM, wrote: > Send Beginners mailing list submissions to > beginners at haskell.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > or, via email, send a message with subject or body 'help' to > beginners-request at haskell.org > > You can reach the person managing the list at > beginners-owner at haskell.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Beginners digest..." > > > Today's Topics: > > 1. Is there an idiom for this? (Mark Carter) > 2. Re: Is there an idiom for this? (emacstheviking) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Mon, 16 Nov 2015 11:44:35 +0000 > From: Mark Carter > To: beginners at haskell.org > Subject: [Haskell-beginners] Is there an idiom for this? > Message-ID: <5649C1A3.1010901 at gmail.com> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > Suppose I want to use an argument twice, as for example in the expression: > (\x -> (pred1 x) and (pred2 x)) > > Is there a shorter way of doing this? > > > ------------------------------ > > Message: 2 > Date: Mon, 16 Nov 2015 11:53:28 +0000 > From: emacstheviking > To: The Haskell-Beginners Mailing List - Discussion of primarily > beginner-level topics related to Haskell > Subject: Re: [Haskell-beginners] Is there an idiom for this? > Message-ID: > 5-8jux3pXyg at mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > I guess it depends on the final use cases... you could use currying to > partially evaluate some stuff ready, locked and loaded as it were but the > example you have given shows to distinct functions pres1 and pred2. > > I guess the short answer is "yes" but it depends on how you do it! > > :) > Sean > > > On 16 November 2015 at 11:44, Mark Carter wrote: > > > Suppose I want to use an argument twice, as for example in the > expression: > > (\x -> (pred1 x) and (pred2 x)) > > > > Is there a shorter way of doing this? > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.haskell.org/pipermail/beginners/attachments/20151116/78b641a6/attachment-0001.html > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > ------------------------------ > > End of Beginners Digest, Vol 89, Issue 28 > ***************************************** > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mike_k_houghton at yahoo.co.uk Tue Nov 17 21:41:20 2015 From: mike_k_houghton at yahoo.co.uk (Mike Houghton) Date: Tue, 17 Nov 2015 21:41:20 +0000 Subject: [Haskell-beginners] Monad for Pair Message-ID: Hi, I have newtype Pair a = P (a, a) deriving (Show) and have made Monoid, Applicative and Functor instances for it. I?m a bit stumped with Monad! instance Monad Pair where return x = P (x, x) and I got brain ache with >>= And really return x = P (x, x) doesn?t seem correct anyway. Would someone please write the Monad with an explanation? Many Thanks Mike From marcin.jan.mrotek at gmail.com Tue Nov 17 22:15:37 2015 From: marcin.jan.mrotek at gmail.com (Marcin Mrotek) Date: Tue, 17 Nov 2015 23:15:37 +0100 Subject: [Haskell-beginners] Monad for Pair In-Reply-To: References: Message-ID: Hello, I'm pretty sure a Pair (like any other fixed-length type, besides the corner case of a single field like in Writer, Identity, etc) can't be a monad. Perhaps instead of struggling with >>=, consider join. It has a type: join :: Monad m => m (m a) -> m a for Pairs that would be join :: Pair (Pair a) -> Pair a join (Pair (Pair a1 a2) (Pair b1 b2)) = Pair _ _ How do you want to fit four values into two boxes? You cannot place any constraints on the type inside the pair, so it can't be a monoid or anything that would let you combine the values somehow. You could only choose two of the values and drop the other two on the floor. Getting back to >>=, it's assumed to follow these laws: 1) return a >>= k = k a 2) m >>= return = m 3) m >>= (\x -> k x >>= h) = (m >>= k) >>= h As for the firs, return a = Pair a a. Then the first two laws become 1) Pair a a >>= k = k a 2) Pair a b >>= (\a -> Pair a a) = Pair a b The first law could work if >>= just chose one of the values arbitrarily. But the second law is a hopeless case. You would need to pick one element of a pair, plug it into a function that repeats the argument, and somehow get back the other element that you've already dropped. Concluding, either I'm sorely mistaken or there indeed isn't a Monad instance for Pair. Best regards, Marcin Mrotek From ky3 at atamo.com Wed Nov 18 07:23:37 2015 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Wed, 18 Nov 2015 14:23:37 +0700 Subject: [Haskell-beginners] Monad for Pair In-Reply-To: References: Message-ID: On Wed, Nov 18, 2015 at 4:41 AM, Mike Houghton wrote: And really return x = P (x, x) doesn?t seem correct anyway. > But if you look at the type, which is essentially "a -> (a,a)" there's only one way to write it, for the same reason that there's only one "a -> a" function. Would someone please write the Monad with an explanation? > Much better if you let us know the source of this problem. Is this an exercise from some book / online course? -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Wed Nov 18 07:44:56 2015 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Wed, 18 Nov 2015 14:44:56 +0700 Subject: [Haskell-beginners] Monad for Pair In-Reply-To: References: Message-ID: On Wed, Nov 18, 2015 at 5:15 AM, Marcin Mrotek wrote: The first law could work if >>= just chose one of the values > arbitrarily. But the second law is a hopeless case. You would need to > pick one element of a pair, plug it into a function that repeats the > argument, and somehow get back the other element that you've already > dropped. > > Concluding, either I'm sorely mistaken or there indeed isn't a Monad > instance for Pair. > Not quite sorely mistaken but there is a glitch in the logic of what you wrote when you returned from join to bind. You might want to try writing out a test instance in full and re-checking the second law. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From marcin.jan.mrotek at gmail.com Wed Nov 18 08:28:22 2015 From: marcin.jan.mrotek at gmail.com (Marcin Mrotek) Date: Wed, 18 Nov 2015 09:28:22 +0100 Subject: [Haskell-beginners] Monad for Pair In-Reply-To: References: Message-ID: > You might want to try writing out a test instance in full and re-checking the second law. Ok, while the part upto Applicative is correct and unambiguous: data Pair a = Pair a a instance Functor Pair where fmap f (Pair a b) = Pair (f a) (f b) instance Applicative Pair where pure a = Pair a a Pair fa fb <*> Pair a b = Pair (fa a) (fb b) there are at least two implementations of Monad (assuming return=pure, also GHC 7.10 allows omitting return and implements it exactly like that): -- implementation (a) instance Monad Pair where Pair a _ >>= k = k a -- implementation (b) instance Monad Pair where Pair _ b >>= k = k b ... neither of which can satisfy the laws. There are more: -- implementation (c) instance Monad Pair where Pair a b >>= k = Pair a' b' where Pair a' _ = k a Pair _ b' = k b -- implementation (d) instance Monad Pair where Pair a b >>= k = Pair a' b' where Pair _ b' = k a Pair a' _ = k b and, well: instance Monad Pair where Pair a b >>= _ = Pair a b Did I miss anything? Now, trying to get the second law to work: a) m >>= return = m Pair a b >>= (\a -> Pair a a) = Pair a b Pair a a = Pair a b contradiction. b) m >>= return = m Pair a b >>= (\a -> Pair a a) = Pair a b Pair b b = Pair a b contradiction. c) m >>= return = m Pair a b >>= (\a -> Pair a a) = Pair a b Pair a b = Pair a b no contradiction this time, I'll write the other laws after I'm done with the second for the other instances. d) m >>= return = m Pair a b >>= (\a -> Pair a a) = Pair a b Pair b a = Pair a b contradiction. e) m >>= return = m trivially correct. Testing the first law for (c) and (e) that passed the second law: c) return a >>= k = k a Pair a a >>= k a = k a --- Pair a' b' = k a where Pair a' _ = k a Pair _ b' = k a --- no contradiction again. e) return a >>= k = k a return a = k a contradiction. Okay, then testing the third law for (c): m >>= (\x -> k x >>= h) = (m >>= k) >>= h Pair a b >>= (\x -> k x >>= h) = (Pair a b >>= k) >>= h (*) Let's again unpack the application of >>= in some pseud-haskell: Pair a1 _ = (\x -> k x >>= h) a = k a >>= h (**) Pair _ b1 = (\x -> k x >>= h) b = k b >> =h Pair a2 _ = k a (***) Pair _ b2 = k b plugging it into (*): Pair a1 b1 = Pair a2 b2 >>= h Unpacking >>= again: Pair a3 _ = h a2 (****) Pair _ b3 = h b2 Pair a1 b1 = Pair a3 b3 Now, testing if a1 = a3, lets bring in (**), (***), and (****): Pair a1 _ = k a >>= h Pair a2 _ = k a Pair a3 _ = h a2 Form the first and the second equations (also using the one for b2 earlier, but it's going to be dropped anyway sooner or later) we get: Pair a1 _ = Pair a2 b2 >>= h Unpacking >>= : Pair a4 _ = h a2 Pair _ b4 = h b2 But from the third equation we know that (Pair a3 _ = h a2) so: Pair a1 _ = Pair a3 _ This does seem to work, I have no idea why. I'm pretty sure there I've made a mistake somewhere. Perhaps I shouldn't do equational reasoning after just getting up, or just use Agda :-/ Best regards, Marcin Mrotek From ky3 at atamo.com Wed Nov 18 08:44:11 2015 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Wed, 18 Nov 2015 15:44:11 +0700 Subject: [Haskell-beginners] Monad for Pair In-Reply-To: References: Message-ID: On Wed, Nov 18, 2015 at 3:28 PM, Marcin Mrotek wrote: This does seem to work, I have no idea why. I'm pretty sure there I've > made a mistake somewhere. Perhaps I shouldn't do equational reasoning > after just getting up, or just use Agda :-/ > Congrats ! Vuvuzela ! If there are bugs in the proof, you can give it to your students to patch up. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From gesh at gesh.uni.cx Wed Nov 18 08:59:10 2015 From: gesh at gesh.uni.cx (Gesh) Date: Wed, 18 Nov 2015 10:59:10 +0200 Subject: [Haskell-beginners] Monad for Pair In-Reply-To: References: Message-ID: <949D67FD-4918-41FE-A1A4-8202126BE5D2@gesh.uni.cx> On November 18, 2015 12:15:37 AM GMT+02:00, Marcin Mrotek wrote: >Hello, > >I'm pretty sure a Pair (like any other fixed-length type, besides the >corner case of a single field like in Writer, Identity, etc) can't be >a monad. Perhaps instead of struggling with >>=, consider join. It has >a type: > >join :: Monad m => m (m a) -> m a > >for Pairs that would be > >join :: Pair (Pair a) -> Pair a >join (Pair (Pair a1 a2) (Pair b1 b2)) = Pair _ _ > >How do you want to fit four values into two boxes? You cannot place >any constraints on the type inside the pair, so it can't be a monoid >or anything that would let you combine the values somehow. You could >only choose two of the values and drop the other two on the floor. > >Getting back to >>=, it's assumed to follow these laws: > >1) return a >>= k = k a >2) m >>= return = m >3) m >>= (\x -> k x >>= h) = (m >>= k) >>= h > >As for the firs, return a = Pair a a. Then the first two laws become > >1) Pair a a >>= k = k a >2) Pair a b >>= (\a -> Pair a a) = Pair a b > >The first law could work if >>= just chose one of the values >arbitrarily. But the second law is a hopeless case. You would need to >pick one element of a pair, plug it into a function that repeats the >argument, and somehow get back the other element that you've already >dropped. > >Concluding, either I'm sorely mistaken or there indeed isn't a Monad >instance for Pair. > >Best regards, >Marcin Mrotek >_______________________________________________ >Beginners mailing list >Beginners at haskell.org >http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners No. Pair can be made into a monad, and this is made clear by realizing that Pair a ~ Bool -> a, so the monad instance for Reader should work here. In fact, this means that any representable functor (i.e. f s.t. f a ~ t-> a for some t) has all instances that Reader r has for fixed r. HTH, Gesh From marcin.jan.mrotek at gmail.com Wed Nov 18 09:36:46 2015 From: marcin.jan.mrotek at gmail.com (Marcin Mrotek) Date: Wed, 18 Nov 2015 10:36:46 +0100 Subject: [Haskell-beginners] Monad for Pair In-Reply-To: <949D67FD-4918-41FE-A1A4-8202126BE5D2@gesh.uni.cx> References: <949D67FD-4918-41FE-A1A4-8202126BE5D2@gesh.uni.cx> Message-ID: > If there are bugs in the proof, you can give it to your students to patch up. If I'll ever have any, they aren't going to be CS students :) > Pair a ~ Bool -> a, so the monad instance for Reader should work here Okay, that makes sense. Sorry for the noise then. Best regards, Marcin Mrotek From mike_k_houghton at yahoo.co.uk Wed Nov 18 18:33:35 2015 From: mike_k_houghton at yahoo.co.uk (Mike Houghton) Date: Wed, 18 Nov 2015 18:33:35 +0000 Subject: [Haskell-beginners] Monad for Pair In-Reply-To: References: Message-ID: <72DBD1D9-80A3-490A-BC79-4731908F1DB6@yahoo.co.uk> 'Much better if you let us know the source of this problem. Is this an exercise from some book / online course?? The source is just me exploring. I first looked at data C a = C a deriving (Show) and made Monad, Applicative, Monoid and Functors for it. So then tried Pair a = P (a, a) and stuck on Monad. Thanks Mike > On 18 Nov 2015, at 07:23, Kim-Ee Yeoh > wrote: > > > On Wed, Nov 18, 2015 at 4:41 AM, Mike Houghton > wrote: > > And really return x = P (x, x) doesn?t seem correct anyway. > > But if you look at the type, which is essentially "a -> (a,a)" there's only one way to write it, for the same reason that there's only one "a -> a" function. > > Would someone please write the Monad with an explanation? > > Much better if you let us know the source of this problem. Is this an exercise from some book / online course? > > -- Kim-Ee > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From mike_k_houghton at yahoo.co.uk Wed Nov 18 18:33:59 2015 From: mike_k_houghton at yahoo.co.uk (Mike Houghton) Date: Wed, 18 Nov 2015 18:33:59 +0000 Subject: [Haskell-beginners] Monad for Pair In-Reply-To: References: Message-ID: <8AF193FC-D5B5-4461-806F-CEE85B3B8EDD@yahoo.co.uk> 'Much better if you let us know the source of this problem. Is this an exercise from some book / online course?? The source is just me exploring. I first looked at data C a = C a deriving (Show) and made Monad, Applicative, Monoid and Functors for it. So then tried Pair a = P (a, a) and stuck on Monad. Thanks Mike > On 18 Nov 2015, at 07:23, Kim-Ee Yeoh > wrote: > > > On Wed, Nov 18, 2015 at 4:41 AM, Mike Houghton > wrote: > > And really return x = P (x, x) doesn?t seem correct anyway. > > But if you look at the type, which is essentially "a -> (a,a)" there's only one way to write it, for the same reason that there's only one "a -> a" function. > > Would someone please write the Monad with an explanation? > > Much better if you let us know the source of this problem. Is this an exercise from some book / online course? > > -- Kim-Ee > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From kolsrud at gmail.com Wed Nov 18 19:35:42 2015 From: kolsrud at gmail.com (=?UTF-8?Q?=C3=98ystein_Kolsrud?=) Date: Wed, 18 Nov 2015 20:35:42 +0100 Subject: [Haskell-beginners] Functional Programming for the Object Oriented Message-ID: I gave a presentation on functional programming a couple of weeks ago that I thought might be of interest to this community as well: https://www.youtube.com/watch?v=I2tMmsZC1ZU It's target audience is programmers familiar with object oriented programming, and it presents how concepts from the functional paradigm are relevant also in most modern OO languages. For more information about the presentation, please refer to the following site: http://www.foocafe.org/previous_event/functional-programming-for-the-object-oriented -- Mvh ?ystein Kolsrud From umairsd at gmail.com Thu Nov 19 01:03:50 2015 From: umairsd at gmail.com (Umair Saeed) Date: Wed, 18 Nov 2015 17:03:50 -0800 Subject: [Haskell-beginners] Applicative Laws for the ((->) r) type Message-ID: Hi all, I'm trying to check that the Applicative laws hold for the function type ((->) r), and here's what I have so far: -- Identiy pure (id) <*> v = v pure (id) <*> v const id <*> v (\x -> const id x (g x)) (\x -> id (g x)) (\x -> g x) g x v -- Homomorphism pure f <*> pure x = pure (f x) pure f <*> pure x const f <*> const x (\y -> const f y (const x y)) (\y -> f (x)) (\_ -> f x) pure (f x) Did I perform the steps for the first two laws correctly? I'm struggling with the interchange & composition laws. For interchange, so far I have the following: -- Interchange u <*> pure y = pure ($y) <*> u u <*> pure y u <*> const y (\x -> g x (const y x)) (\x -> g x y) -- I'm not sure how to proceed beyond this point. I would appreciate any help for the steps to verify the Interchange & Composition applicative laws for the ((->) r) type. Thank you, ~Umair -------------- next part -------------- An HTML attachment was scrubbed... URL: From chak at justtesting.org Thu Nov 19 03:26:31 2015 From: chak at justtesting.org (Manuel M T Chakravarty) Date: Thu, 19 Nov 2015 14:26:31 +1100 Subject: [Haskell-beginners] Learning Haskell: Higher-order Functions Message-ID: <86FC1F7D-5B00-46CF-90FC-53305562908F@justtesting.org> We have got a new tutorial chapter on ?Higher-order Functions & Combinators?: http://blog.haskellformac.com/blog/higher-order-functions-combinators Hope you enjoy it! Manuel From ky3 at atamo.com Thu Nov 19 06:34:48 2015 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Thu, 19 Nov 2015 13:34:48 +0700 Subject: [Haskell-beginners] Monad for Pair In-Reply-To: <72DBD1D9-80A3-490A-BC79-4731908F1DB6@yahoo.co.uk> References: <72DBD1D9-80A3-490A-BC79-4731908F1DB6@yahoo.co.uk> Message-ID: On Thu, Nov 19, 2015 at 1:33 AM, Mike Houghton wrote: The source is just me exploring. > Nice. > I first looked at > > data C a = C a deriving (Show) > > and made Monad, Applicative, Monoid and Functors for it. > Even though the null-effect instances for the identity functor are trivial, there's value in writing them out, especially for the motivated. But how do you take an arbitrary type and turn it into a monoid? -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From nicohertzulis at gmail.com Thu Nov 19 08:57:37 2015 From: nicohertzulis at gmail.com (=?UTF-8?Q?Nicol=C3=A1s_Hertzulis?=) Date: Thu, 19 Nov 2015 05:57:37 -0300 Subject: [Haskell-beginners] Bug in solution for problem 19 Message-ID: The penultimate solution for problem 19 of Ninety-Nine Haskell Problems is giving the result for the opposite of the given N. e.g. rotate "abcdefgh" (-3) gives the result for rotate "abcdefgh" 3 Here's the problem https://wiki.haskell.org/99_questions/11_to_20 and the solution https://wiki.haskell.org/99_questions/Solutions/19 I think it could be solved like this: rotate xs n | n <= 0 = (reverse . take (negate n) . reverse $ xs) ++ (reverse . drop (negate n) . reverse $ xs) | n > 0 = (drop n xs) ++ (take n xs) I know it's not great, just keeping the spirit of the original solution Is this the right list for reporting this kind of bugs? Nicol?s -------------- next part -------------- An HTML attachment was scrubbed... URL: From mike_k_houghton at yahoo.co.uk Thu Nov 19 18:30:54 2015 From: mike_k_houghton at yahoo.co.uk (Mike Houghton) Date: Thu, 19 Nov 2015 18:30:54 +0000 Subject: [Haskell-beginners] Monad for Pair In-Reply-To: References: <72DBD1D9-80A3-490A-BC79-4731908F1DB6@yahoo.co.uk> Message-ID: "But how do you take an arbitrary type and turn it into a monoid?? I didn?t - I must have been dreaming about Haskell at that point :) (My wife once dreamt she was a C compiler - go figure? C !!??) No, just Monad, Applicative and Functor - my mistake. Thanks Mike > On 19 Nov 2015, at 06:34, Kim-Ee Yeoh wrote: > > > On Thu, Nov 19, 2015 at 1:33 AM, Mike Houghton > wrote: > > The source is just me exploring. > > Nice. > > I first looked at > > data C a = C a deriving (Show) > > and made Monad, Applicative, Monoid and Functors for it. > > Even though the null-effect instances for the identity functor are trivial, there's value in writing them out, especially for the motivated. > > But how do you take an arbitrary type and turn it into a monoid? > > -- Kim-Ee > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From mike_k_houghton at yahoo.co.uk Thu Nov 19 18:31:23 2015 From: mike_k_houghton at yahoo.co.uk (Mike Houghton) Date: Thu, 19 Nov 2015 18:31:23 +0000 Subject: [Haskell-beginners] Monad for Pair In-Reply-To: References: Message-ID: <9A6E25AF-1538-441C-9992-9CC586EB69AB@yahoo.co.uk> Thanks for this - I?ll work through it. Mike > On 18 Nov 2015, at 08:28, Marcin Mrotek wrote: > >> You might want to try writing out a test instance in full and re-checking the second law. > > Ok, while the part upto Applicative is correct and unambiguous: > > data Pair a = Pair a a > > instance Functor Pair where > fmap f (Pair a b) = Pair (f a) (f b) > > instance Applicative Pair where > pure a = Pair a a > Pair fa fb <*> Pair a b = Pair (fa a) (fb b) > > there are at least two implementations of Monad (assuming return=pure, > also GHC 7.10 allows omitting return and implements it exactly like > that): > > -- implementation (a) > instance Monad Pair where > Pair a _ >>= k = k a > > -- implementation (b) > instance Monad Pair where > Pair _ b >>= k = k b > > ... neither of which can satisfy the laws. There are more: > > -- implementation (c) > instance Monad Pair where > Pair a b >>= k = Pair a' b' > where > Pair a' _ = k a > Pair _ b' = k b > > -- implementation (d) > instance Monad Pair where > Pair a b >>= k = Pair a' b' > where > Pair _ b' = k a > Pair a' _ = k b > > and, well: > > instance Monad Pair where > Pair a b >>= _ = Pair a b > > Did I miss anything? Now, trying to get the second law to work: > > a) m >>= return = m > Pair a b >>= (\a -> Pair a a) = Pair a b > Pair a a = Pair a b > contradiction. > > b) m >>= return = m > Pair a b >>= (\a -> Pair a a) = Pair a b > Pair b b = Pair a b > contradiction. > > c) m >>= return = m > Pair a b >>= (\a -> Pair a a) = Pair a b > Pair a b = Pair a b > no contradiction this time, I'll write the other laws after I'm done > with the second for the other instances. > > d) m >>= return = m > Pair a b >>= (\a -> Pair a a) = Pair a b > Pair b a = Pair a b > contradiction. > > e) m >>= return = m > trivially correct. > > Testing the first law for (c) and (e) that passed the second law: > > c) return a >>= k = k a > Pair a a >>= k a = k a > --- > Pair a' b' = k a > where > Pair a' _ = k a > Pair _ b' = k a > --- > no contradiction again. > > e) return a >>= k = k a > return a = k a > contradiction. > > Okay, then testing the third law for (c): > > m >>= (\x -> k x >>= h) = (m >>= k) >>= h > > Pair a b >>= (\x -> k x >>= h) = (Pair a b >>= k) >>= h (*) > > Let's again unpack the application of >>= in some pseud-haskell: > > Pair a1 _ = (\x -> k x >>= h) a = k a >>= h (**) > Pair _ b1 = (\x -> k x >>= h) b = k b >> =h > > Pair a2 _ = k a (***) > Pair _ b2 = k b > > plugging it into (*): > > Pair a1 b1 = Pair a2 b2 >>= h > > Unpacking >>= again: > > Pair a3 _ = h a2 (****) > Pair _ b3 = h b2 > > Pair a1 b1 = Pair a3 b3 > > Now, testing if a1 = a3, lets bring in (**), (***), and (****): > > Pair a1 _ = k a >>= h > Pair a2 _ = k a > Pair a3 _ = h a2 > > Form the first and the second equations (also using the one for b2 > earlier, but it's going to be dropped anyway sooner or later) we get: > > Pair a1 _ = Pair a2 b2 >>= h > > Unpacking >>= : > > Pair a4 _ = h a2 > Pair _ b4 = h b2 > > But from the third equation we know that (Pair a3 _ = h a2) so: > > Pair a1 _ = Pair a3 _ > > This does seem to work, I have no idea why. I'm pretty sure there I've > made a mistake somewhere. Perhaps I shouldn't do equational reasoning > after just getting up, or just use Agda :-/ > > Best regards, > Marcin Mrotek > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From marcin.jan.mrotek at gmail.com Thu Nov 19 18:56:39 2015 From: marcin.jan.mrotek at gmail.com (Marcin Mrotek) Date: Thu, 19 Nov 2015 19:56:39 +0100 Subject: [Haskell-beginners] Monad for Pair In-Reply-To: <9A6E25AF-1538-441C-9992-9CC586EB69AB@yahoo.co.uk> References: <9A6E25AF-1538-441C-9992-9CC586EB69AB@yahoo.co.uk> Message-ID: > Thanks for this - I?ll work through it. Yeah, apparently I accidentaly wrote a correct instance there. You can also use what Gesh wrote, and try to derive an instance from something like: tabulate :: (Bool -> a) -> Pair a tabulate f = Pair (f True) (f False) index :: Pair a -> Bool -> a index (Pair a _) True = a index (Pair _ b) False = b instance Applicative Pair where pure = tabulate . pure fp <*> fa = tabulate $ index fp <*> index fa instance Monad Pair where m >>= f = tabulate $ index m >>= index . f The instances for a function are (in pseudo-Haskell, I don't think GHC accepts (a ->) instead of ((->) a), but it looks cleaner that way) instance Applicative (a ->) where pure = const f <*> g = \x -> f x (g x) instance Monad (a ->) where f >>= k = \ r -> k (f r) r > My wife once dreamt she was a C compiler - go figure? C !!?? C isn't exactly known for type safety, so things can indeed get Kafkaesque sometimes. Best regards, Marcin Mrotek From martin at vlkk.cz Fri Nov 20 12:14:25 2015 From: martin at vlkk.cz (Martin Vlk) Date: Fri, 20 Nov 2015 12:14:25 +0000 Subject: [Haskell-beginners] Ambiguous type of WriterT result I am not using Message-ID: <564F0EA1.7000203@vlkk.cz> Hi I have two functions, foldrEntries and foldrEntriesW, where the latter is a WriterT version of the former. Here are the type signatures: foldrEntries :: (Entry -> a -> a) -> a -> (String -> a) -> Entries -> a foldrEntriesW :: (Monoid w, Monad m) => (Entry -> a -> WriterT w m a) -> WriterT w m a -> (String -> WriterT w m a) -> Entries -> WriterT w m a I want to implement foldrEntries in terms of foldrEntriesW using the Identity monad and ignore/not use the writer result. I am doing this in order to reuse the foldrEntriesW implementation and avoid code duplication. This is what I have so far: http://lpaste.net/145641 But the compiler complains about ambiguous type for the writer reult I am ignoring (message in the above lpaste). Normally I think the way around this is to provide explicit type annotation for "foldIt", but in this case the result type depends on the type of "a" in foldrEntries type and I don't know how to express this and make the compiler happy. (I was able to make it work by calling "tell ()", basically writing a dummy value, which lets compiler know what the type is, but this is not so good - I don't want to make artificial function calls like this.) Can anybody help me with that? Many Thanks Martin From toad3k at gmail.com Fri Nov 20 15:46:38 2015 From: toad3k at gmail.com (David McBride) Date: Fri, 20 Nov 2015 10:46:38 -0500 Subject: [Haskell-beginners] Ambiguous type of WriterT result I am not using In-Reply-To: <564F0EA1.7000203@vlkk.cz> References: <564F0EA1.7000203@vlkk.cz> Message-ID: The problem is in your string -> WriterT w m a. It needs to know what the w is. It knows its a monoid but doesn't know anything else about it. The simplest thing is to just tell it what it is. foldrEntries :: (Entry -> a -> a) -> a -> (String -> a) -> Entries -> a foldrEntries next done fail' es = runIdentity $ return . fst =<< runWriterT foldIt where foldIt = foldrEntriesW (\e -> return . next e) (return done) ((return :: Monad m => a -> WriterT () m a) . fail') es A second option is to give foldIt a type signature. Unfortunately if you want the a in foldIt to match the a in foldEntries, you have to use scoped type variables extension. Normally the two signatures are not related and the compiler figures both a's are not the same as each other. {-# LANGUAGE ScopedTypeVariables #-} ... foldrEntries :: forall a. (Entry -> a -> a) -> a -> (String -> a) -> Entries -> a foldrEntries next done fail' es = runIdentity $ return . fst =<< runWriterT foldIt where foldIt :: Monad m => WriterT () m a foldIt = foldrEntriesW (\e -> return . next e) (return done) (return . fail') es On Fri, Nov 20, 2015 at 7:14 AM, Martin Vlk wrote: > Hi I have two functions, foldrEntries and foldrEntriesW, where the > latter is a WriterT version of the former. Here are the type signatures: > > foldrEntries :: (Entry -> a -> a) -> > a -> > (String -> a) -> > Entries -> > a > > foldrEntriesW :: (Monoid w, Monad m) => > (Entry -> a -> WriterT w m a) -> > WriterT w m a -> > (String -> WriterT w m a) -> > Entries -> > WriterT w m a > > I want to implement foldrEntries in terms of foldrEntriesW using the > Identity monad and ignore/not use the writer result. I am doing this in > order to reuse the foldrEntriesW implementation and avoid code duplication. > > This is what I have so far: > http://lpaste.net/145641 > > But the compiler complains about ambiguous type for the writer reult I > am ignoring (message in the above lpaste). > > Normally I think the way around this is to provide explicit type > annotation for "foldIt", but in this case the result type depends on the > type of "a" in foldrEntries type and I don't know how to express this > and make the compiler happy. > > (I was able to make it work by calling "tell ()", basically writing a > dummy value, which lets compiler know what the type is, but this is not > so good - I don't want to make artificial function calls like this.) > > Can anybody help me with that? > > Many Thanks > Martin > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Fri Nov 20 17:21:52 2015 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Sat, 21 Nov 2015 00:21:52 +0700 Subject: [Haskell-beginners] Ambiguous type of WriterT result I am not using In-Reply-To: <564F0EA1.7000203@vlkk.cz> References: <564F0EA1.7000203@vlkk.cz> Message-ID: Hi Martin, But the compiler complains about ambiguous type for the writer reult I > am ignoring (message in the above lpaste). > There are a number of types going on here, and the one that's ambiguous is the monoid w in WriterT w m a. > Normally I think the way around this is to provide explicit type > annotation for "foldIt", but in this case the result type depends on the > type of "a" in foldrEntries type and I don't know how to express this > and make the compiler happy. > David's ScopedTypeVariables solution is perfectly cromulent. Here's another one without any pragmas: foldrEntries :: (Entry -> a -> a) -> a -> (String -> a) -> Entries -> a foldrEntries next done fail' = isoR . foldrEntriesW (isoL .: next) (isoL done) (isoL . fail') where isoL :: a -> WriterT () Identity a isoL = return isoR :: WriterT () Identity a -> a isoR = fst . runIdentity . runWriterT The (.:) is from Data.Composition. The isoL and isoR witness the isomorphism, and foldrEntries is written in a point-minimized form that makes it transparent that it's a specialization of foldrEntriesW. Do eschew verbosities like "return . fst =<< runWriterT". (Hlint should be programmed to catch this. It doesn't yet.) A return that's too near a monadic bind sets off alarms among professional haskell engineers. > (I was able to make it work by calling "tell ()", basically writing a > dummy value, which lets compiler know what the type is, but this is not > so good - I don't want to make artificial function calls like this.) > Good call. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From jykang22 at gmail.com Sat Nov 21 02:38:44 2015 From: jykang22 at gmail.com (Jeon-Young Kang) Date: Fri, 20 Nov 2015 21:38:44 -0500 Subject: [Haskell-beginners] RDF with Haskell Message-ID: Hello. I am a newbie learning Haskell. I'd like to import RDF in Haskell as well as to do SPARQL. I went through RDF4H, Swish, and so on. But it is still difficult to understand them for me. Anyone can suggest me to learn that? or recommend any kinds of books or tutorials? Sincerely, Jeon-Young -- -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjcorso at eecs.umich.edu Sat Nov 21 13:28:01 2015 From: jjcorso at eecs.umich.edu (Jason J. Corso) Date: Sat, 21 Nov 2015 08:28:01 -0500 Subject: [Haskell-beginners] help with type error in a wxHaskell program Message-ID: Hi: I'm new to Haskell and to wxHaskell (but found playing with wxHaskell to be a nice mid-ground between my years of imperative experience and the pure functional). Thanks for the help. I wrote the following code to create a set of staticText widgets by mapping the layout over a list. Easy enough... module Main where import Graphics.UI.WX main :: IO () main = start gui gui :: IO () gui = do f <- frame let s = map (\t -> staticText f [text := show t]) [1..10] set f [layout := margin 10 ( row 2 $ map (\x -> (widget x)) s)] But, I get a type error that I do not understand Couldn't match expected type ?IO (Window a0)? with actual type ?[Prop (Frame ())] -> IO (Frame ())? Probable cause: ?frame? is applied to too few arguments Thank you in advance, Jason From toad3k at gmail.com Sat Nov 21 15:02:39 2015 From: toad3k at gmail.com (David McBride) Date: Sat, 21 Nov 2015 10:02:39 -0500 Subject: [Haskell-beginners] help with type error in a wxHaskell program In-Reply-To: References: Message-ID: The type of frame according to the documentation is frame :: [Prop (Frame ())] -> IO ( Frame ()). Maybe the documentation you are looking at is out of date? On Sat, Nov 21, 2015 at 8:28 AM, Jason J. Corso wrote: > Hi: > > I'm new to Haskell and to wxHaskell (but found playing with wxHaskell > to be a nice mid-ground between my years of imperative experience and > the pure functional). Thanks for the help. > > I wrote the following code to create a set of staticText widgets by > mapping the layout over a list. Easy enough... > > module Main where > import Graphics.UI.WX > main :: IO () > main > = start gui > gui :: IO () > gui = do > f <- frame > let s = map (\t -> staticText f [text := show t]) [1..10] > set f [layout := margin 10 ( row 2 $ map (\x -> (widget x)) s)] > > > But, I get a type error that I do not understand > > Couldn't match expected type ?IO (Window a0)? > with actual type ?[Prop (Frame ())] -> IO (Frame ())? > Probable cause: ?frame? is applied to too few arguments > > > Thank you in advance, > Jason > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mihai.maruseac at gmail.com Sat Nov 21 18:13:36 2015 From: mihai.maruseac at gmail.com (Mihai Maruseac) Date: Sat, 21 Nov 2015 13:13:36 -0500 Subject: [Haskell-beginners] NNOUNCE: Haskell Communities and Activities Report (29th ed., November 2015) Message-ID: On behalf of all the contributors, we are pleased to announce that the Haskell Communities and Activities Report (29th edition, November 2015) is now available, in PDF and HTML formats: http://haskell.org/communities/11-2015/report.pdf http://haskell.org/communities/11-2015/html/report.html Many thanks go to all the people that contributed to this report, both directly, by sending in descriptions, and indirectly, by doing all the interesting things that are reported. We hope you will find it as interesting a read as we did. If you have not encountered the Haskell Communities and Activities Reports before, you may like to know that the first of these reports was published in November 2001. Their goal is to improve the communication between the increasingly diverse groups, projects, and individuals working on, with, or inspired by Haskell. The idea behind these reports is simple: Every six months, a call goes out to all of you enjoying Haskell to contribute brief summaries of your own area of work. Many of you respond (eagerly, unprompted, and sometimes in time for the actual deadline) to the call. The editors collect all the contributions into a single report and feed that back to the community. When we try for the next update, six months from now, you might want to report on your own work, project, research area or group as well. So, please put the following into your diaries now: ======================================== End of March 2015: target deadline for contributions to the May 2015 edition of the HCAR Report ======================================== Unfortunately, many Haskellers working on interesting projects are so busy with their work that they seem to have lost the time to follow the Haskell related mailing lists and newsgroups, and have trouble even finding time to report on their work. If you are a member, user or friend of a project so burdened, please find someone willing to make time to report and ask them to "register" with the editors for a simple e-mail reminder in March (you could point us to them as well, and we can then politely ask if they want to contribute, but it might work better if you do the initial asking). Of course, they will still have to find the ten to fifteen minutes to draw up their report, but maybe we can increase our coverage of all that is going on in the community. Feel free to circulate this announcement further in order to reach people who might otherwise not see it. Enjoy! Mihai Maruseac -- Mihai Maruseac (MM) "If you can't solve a problem, then there's an easier problem you can solve: find it." -- George Polya From jykang22 at gmail.com Sat Nov 21 19:13:15 2015 From: jykang22 at gmail.com (Jeon-Young Kang) Date: Sat, 21 Nov 2015 14:13:15 -0500 Subject: [Haskell-beginners] Warning: Tab Character Message-ID: Hello everyone. I am a newbie of Haskell, using Textmate on mac. I got the following warning. How can I fix it? Warning: Tab character Ok, modules loaded: Main. Sincerely, Young -------------- next part -------------- An HTML attachment was scrubbed... URL: From dutch.glory at yahoo.com Sat Nov 21 19:29:17 2015 From: dutch.glory at yahoo.com (=?UTF-8?Q?Andr=c3=a9_Verwijs?=) Date: Sat, 21 Nov 2015 20:29:17 +0100 Subject: [Haskell-beginners] could not install "process-leksah" due to dependencies errors.... Message-ID: <5650C60D.8050804@yahoo.com> remote-repos: hackage.haskell.org http://hackage.haskell.org/packages/archive >> cabal install leksah process-leksah Resolving dependencies... cabal: Could not resolve dependencies: trying: leksah-0.15.1.4 (user goal) trying: hlint-1.9.23 (dependency of leksah-0.15.1.4) next goal: haskell-src-exts (dependency of leksah-0.15.1.4) rejecting: haskell-src-exts-1.16.0.1/installed-911... (conflict: hlint => haskell-src-exts>=1.17 && <1.18) rejecting: haskell-src-exts-1.17.0 (conflict: leksah => haskell-src-exts>=1.13.5 && <1.17) rejecting: haskell-src-exts-1.16.0.1, 1.16.0, 1.15.0.1, 1.15.0, 1.14.0.1, 1.14.0, 1.13.5 (conflict: hlint => haskell-src-exts>=1.17 && <1.18) rejecting: haskell-src-exts-1.13.4, 1.13.3, 1.13.2, 1.13.1, 1.13.0, 1.12.0, 1.11.1, 1.10.2, 1.10.1, 1.10.0, 1.9.6, 1.9.5, 1.9.4, 1.9.3, 1.9.0, 1.8.2, 1.8.1, 1.8.0, 1.7.2, 1.7.1, 1.7.0, 1.6.1, 1.6.0, 1.5.3, 1.5.2, 1.5.1, 1.5.0, 1.4.0, 1.3.5, 1.3.4, 1.3.3, 1.3.2, 1.3.1, 1.3.0, 1.2.0, 1.1.4, 1.1.3.1, 1.1.3, 1.1.1, 1.1.0, 1.0.1, 1.0.0, 0.5.7, 0.5.6, 0.5.5, 0.5.4, 0.5.3, 0.5.2, 0.4.8, 0.4.6, 0.4.5, 0.4.4.1, 0.4.4, 0.4.3.1, 0.4.3, 0.4.2, 0.4.1, 0.3.12, 0.3.11, 0.3.10, 0.3.9, 0.3.7, 0.3.5, 0.3.4, 0.3.3, 0.3.2, 0.2.1 (conflict: leksah => haskell-src-exts>=1.13.5 && <1.17) Backjump limit reached (change with --max-backjumps). From dutch.glory at yahoo.com Sat Nov 21 19:52:57 2015 From: dutch.glory at yahoo.com (=?UTF-8?Q?Andr=c3=a9_Verwijs?=) Date: Sat, 21 Nov 2015 20:52:57 +0100 Subject: [Haskell-beginners] could not install "process-leksah" due to dependencies errors.... Message-ID: <5650CB99.3040302@yahoo.com> OS: OpenSUSE tumbleweed 2015-11-18 Plasma 5.4.2 QT version: 5.5.1 Kernel: 4.3.0-2 (needed for building from source) gtksourceview-devel 3.18.1-1.1 libwebkitgtk-devel 2.4.9-3.2 From martin at vlkk.cz Sat Nov 21 20:09:44 2015 From: martin at vlkk.cz (Martin Vlk) Date: Sat, 21 Nov 2015 20:09:44 +0000 Subject: [Haskell-beginners] Ambiguous type of WriterT result I am not using In-Reply-To: References: <564F0EA1.7000203@vlkk.cz> Message-ID: <5650CF88.8030404@vlkk.cz> David, Kim-Ee, thank you both very much - this really helped make my code good looking! Martin Kim-Ee Yeoh: > Hi Martin, > > But the compiler complains about ambiguous type for the writer reult I > am ignoring (message in the above lpaste). > > > There are a number of types going on here, and the one that's ambiguous > is the monoid w in WriterT w m a. > > > Normally I think the way around this is to provide explicit type > annotation for "foldIt", but in this case the result type depends on the > type of "a" in foldrEntries type and I don't know how to express this > and make the compiler happy. > > > David's ScopedTypeVariables solution is perfectly cromulent. Here's > another one without any pragmas: > > foldrEntries :: > (Entry -> a -> a) > -> a > -> (String -> a) > -> Entries > -> a > foldrEntries next done fail' = > isoR . foldrEntriesW (isoL .: next) (isoL done) (isoL . fail') > where > isoL :: a -> WriterT () Identity a > isoL = return > isoR :: WriterT () Identity a -> a > isoR = fst . runIdentity . runWriterT > > The (.:) is from Data.Composition. > > The isoL and isoR witness the isomorphism, and foldrEntries is written > in a point-minimized form that makes it transparent that it's a > specialization of foldrEntriesW. > > Do eschew verbosities like "return . fst =<< runWriterT". (Hlint should > be programmed to catch this. It doesn't yet.) A return that's too near a > monadic bind sets off alarms among professional haskell engineers. > > > (I was able to make it work by calling "tell ()", basically writing a > dummy value, which lets compiler know what the type is, but this is not > so good - I don't want to make artificial function calls like this.) > > > Good call. > > -- Kim-Ee > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From strombrg at gmail.com Sat Nov 21 20:14:09 2015 From: strombrg at gmail.com (Dan Stromberg) Date: Sat, 21 Nov 2015 12:14:09 -0800 Subject: [Haskell-beginners] Warning: Tab Character In-Reply-To: References: Message-ID: Perhaps enable soft tabs? https://manual.macromates.com/en/working_with_text This is an issue in Python too (at least from PEP8's perspective) - but note that many "make" programs require tabs instead of spaces. On Sat, Nov 21, 2015 at 11:13 AM, Jeon-Young Kang wrote: > Hello everyone. > > > I am a newbie of Haskell, using Textmate on mac. > > > I got the following warning. How can I fix it? > > > Warning: > > Tab character > > Ok, modules loaded: Main. > > > Sincerely, > Young > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Dan Stromberg -------------- next part -------------- An HTML attachment was scrubbed... URL: From jykang22 at gmail.com Sat Nov 21 20:36:02 2015 From: jykang22 at gmail.com (Jeon-Young Kang) Date: Sat, 21 Nov 2015 15:36:02 -0500 Subject: [Haskell-beginners] Warning: Tab Character In-Reply-To: References: Message-ID: I've tried to choose "instead of spaces". But there is no option of mine (Textmate 2 beta). On Sat, Nov 21, 2015 at 3:14 PM, Dan Stromberg wrote: > > Perhaps enable soft tabs? > https://manual.macromates.com/en/working_with_text > > This is an issue in Python too (at least from PEP8's perspective) - but > note that many "make" programs require tabs instead of spaces. > > On Sat, Nov 21, 2015 at 11:13 AM, Jeon-Young Kang > wrote: > >> Hello everyone. >> >> >> I am a newbie of Haskell, using Textmate on mac. >> >> >> I got the following warning. How can I fix it? >> >> >> Warning: >> >> Tab character >> >> Ok, modules loaded: Main. >> >> >> Sincerely, >> Young >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > > -- > Dan Stromberg > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Department of Geography State University of New York at Buffalo jykang22 at gmail.com Jeon-Young Kang -------------- next part -------------- An HTML attachment was scrubbed... URL: From kaddkaka at gmail.com Sat Nov 21 23:01:33 2015 From: kaddkaka at gmail.com (David Moberg) Date: Sun, 22 Nov 2015 00:01:33 +0100 Subject: [Haskell-beginners] Warning: Tab Character In-Reply-To: References: Message-ID: Have you found "soft tabs"? That option will make TextMate use spaces instead of tab characters. Read 4.11 "Using Spaces Instead of Tabs" in Dan Strombergs link for instrucitons. 2015-11-21 21:36 GMT+01:00 Jeon-Young Kang : > I've tried to choose "instead of spaces". But there is no option of mine > (Textmate 2 beta). > > On Sat, Nov 21, 2015 at 3:14 PM, Dan Stromberg wrote: > >> >> Perhaps enable soft tabs? >> https://manual.macromates.com/en/working_with_text >> >> This is an issue in Python too (at least from PEP8's perspective) - but >> note that many "make" programs require tabs instead of spaces. >> >> On Sat, Nov 21, 2015 at 11:13 AM, Jeon-Young Kang >> wrote: >> >>> Hello everyone. >>> >>> >>> I am a newbie of Haskell, using Textmate on mac. >>> >>> >>> I got the following warning. How can I fix it? >>> >>> >>> Warning: >>> >>> Tab character >>> >>> Ok, modules loaded: Main. >>> >>> >>> Sincerely, >>> Young >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> >> >> -- >> Dan Stromberg >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > > -- > Department of Geography > State University of New York at Buffalo > > jykang22 at gmail.com > > Jeon-Young Kang > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjakway at nyu.edu Sat Nov 21 23:34:10 2015 From: tjakway at nyu.edu (Thomas Jakway) Date: Sat, 21 Nov 2015 18:34:10 -0500 Subject: [Haskell-beginners] Warning: Tab Character In-Reply-To: Message-ID: Why would make require tabs...? Admittedly it's been a long time since I've written any makefiles by hand but I always use spaces instead of tabs and have never had any problems. On Nov 21, 2015 6:01 PM, David Moberg wrote: > > Have you found "soft tabs"? That option will make?TextMate use spaces instead of tab characters. Read?4.11 "Using Spaces Instead of Tabs" in Dan Strombergs link for instrucitons. > > 2015-11-21 21:36 GMT+01:00 Jeon-Young Kang : >> >> I've tried to choose "instead of spaces". But there is no option of mine (Textmate 2 beta). >> >> On Sat, Nov 21, 2015 at 3:14 PM, Dan Stromberg wrote: >>> >>> >>> Perhaps enable soft tabs? >>> https://manual.macromates.com/en/working_with_text >>> >>> This is an issue in Python too (at least from PEP8's perspective) - but note that many "make" programs require tabs instead of spaces. >>> >>> On Sat, Nov 21, 2015 at 11:13 AM, Jeon-Young Kang wrote: >>>> >>>> Hello everyone. >>>> >>>> >>>> I am a newbie of Haskell, using Textmate on mac. >>>> >>>> >>>> I got the following warning. How can I fix it? >>>> >>>> >>>> Warning: >>>> >>>> ? ? Tab character >>>> >>>> Ok, modules loaded: Main. >>>> >>>> >>>> >>>> Sincerely, >>>> Young >>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>> >>> >>> >>> -- >>> Dan Stromberg >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >> >> >> >> -- >> Department of Geography >> State University of New York at Buffalo >> >> jykang22 at gmail.com >> ? >> Jeon-Young Kang >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > From jykang22 at gmail.com Sat Nov 21 23:37:02 2015 From: jykang22 at gmail.com (Jeon-Young Kang) Date: Sat, 21 Nov 2015 18:37:02 -0500 Subject: [Haskell-beginners] Warning: Tab Character In-Reply-To: References: Message-ID: Thank you all. I found out the way to replacing Tab with Space. On Sat, Nov 21, 2015 at 6:34 PM, Thomas Jakway wrote: > Why would make require tabs...? > Admittedly it's been a long time since I've written any makefiles by hand > but I always use spaces instead of tabs and have never had any problems. > > On Nov 21, 2015 6:01 PM, David Moberg wrote: > > > > Have you found "soft tabs"? That option will make TextMate use spaces > instead of tab characters. Read 4.11 "Using Spaces Instead of Tabs" in Dan > Strombergs link for instrucitons. > > > > 2015-11-21 21:36 GMT+01:00 Jeon-Young Kang : > >> > >> I've tried to choose "instead of spaces". But there is no option of > mine (Textmate 2 beta). > >> > >> On Sat, Nov 21, 2015 at 3:14 PM, Dan Stromberg > wrote: > >>> > >>> > >>> Perhaps enable soft tabs? > >>> https://manual.macromates.com/en/working_with_text > >>> > >>> This is an issue in Python too (at least from PEP8's perspective) - > but note that many "make" programs require tabs instead of spaces. > >>> > >>> On Sat, Nov 21, 2015 at 11:13 AM, Jeon-Young Kang > wrote: > >>>> > >>>> Hello everyone. > >>>> > >>>> > >>>> I am a newbie of Haskell, using Textmate on mac. > >>>> > >>>> > >>>> I got the following warning. How can I fix it? > >>>> > >>>> > >>>> Warning: > >>>> > >>>> Tab character > >>>> > >>>> Ok, modules loaded: Main. > >>>> > >>>> > >>>> > >>>> Sincerely, > >>>> Young > >>>> > >>>> _______________________________________________ > >>>> Beginners mailing list > >>>> Beginners at haskell.org > >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > >>>> > >>> > >>> > >>> > >>> -- > >>> Dan Stromberg > >>> > >>> _______________________________________________ > >>> Beginners mailing list > >>> Beginners at haskell.org > >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > >>> > >> > >> > >> > >> -- > >> Department of Geography > >> State University of New York at Buffalo > >> > >> jykang22 at gmail.com > >> > >> Jeon-Young Kang > >> > >> _______________________________________________ > >> Beginners mailing list > >> Beginners at haskell.org > >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > >> > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Department of Geography State University of New York at Buffalo jykang22 at gmail.com Jeon-Young Kang -------------- next part -------------- An HTML attachment was scrubbed... URL: From strombrg at gmail.com Sun Nov 22 00:44:21 2015 From: strombrg at gmail.com (Dan Stromberg) Date: Sat, 21 Nov 2015 16:44:21 -0800 Subject: [Haskell-beginners] Warning: Tab Character In-Reply-To: References: Message-ID: I believe the first version of make required tabs, but some subsequent versions have relaxed that requirement to make things easier. Here's an example on a Linux Mint system (the 20's are of course spaces) : $ od -cx < Makefile cmd output started 2015 Sat Nov 21 04:39:47 PM PST 0000000 \n g o : \n . / t \n \n 670a 3a6f 200a 2020 2e20 742f 0a0a 0000016 above cmd output done 2015 Sat Nov 21 04:39:47 PM PST dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 $ make cmd output started 2015 Sat Nov 21 04:39:48 PM PST Makefile:3: *** missing separator. Stop. above cmd output done 2015 Sat Nov 21 04:39:48 PM PST dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 $ make --version cmd output started 2015 Sat Nov 21 04:39:53 PM PST GNU Make 3.81 Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This program built for i686-pc-linux-gnu above cmd output done 2015 Sat Nov 21 04:39:53 PM PST dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 I'll add that vim's Makefile syntax highlighting puts the space-indented line in red, suggesting an error. Changing the spaces to a single tab makes the red go away. HTH On Sat, Nov 21, 2015 at 3:34 PM, Thomas Jakway wrote: > Why would make require tabs...? > Admittedly it's been a long time since I've written any makefiles by hand > but I always use spaces instead of tabs and have never had any problems. > > On Nov 21, 2015 6:01 PM, David Moberg wrote: > > > > Have you found "soft tabs"? That option will make TextMate use spaces > instead of tab characters. Read 4.11 "Using Spaces Instead of Tabs" in Dan > Strombergs link for instrucitons. > > > > 2015-11-21 21:36 GMT+01:00 Jeon-Young Kang : > >> > >> I've tried to choose "instead of spaces". But there is no option of > mine (Textmate 2 beta). > >> > >> On Sat, Nov 21, 2015 at 3:14 PM, Dan Stromberg > wrote: > >>> > >>> > >>> Perhaps enable soft tabs? > >>> https://manual.macromates.com/en/working_with_text > >>> > >>> This is an issue in Python too (at least from PEP8's perspective) - > but note that many "make" programs require tabs instead of spaces. > >>> > >>> On Sat, Nov 21, 2015 at 11:13 AM, Jeon-Young Kang > wrote: > >>>> > >>>> Hello everyone. > >>>> > >>>> > >>>> I am a newbie of Haskell, using Textmate on mac. > >>>> > >>>> > >>>> I got the following warning. How can I fix it? > >>>> > >>>> > >>>> Warning: > >>>> > >>>> Tab character > >>>> > >>>> Ok, modules loaded: Main. > >>>> > >>>> > >>>> > >>>> Sincerely, > >>>> Young > >>>> > >>>> _______________________________________________ > >>>> Beginners mailing list > >>>> Beginners at haskell.org > >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > >>>> > >>> > >>> > >>> > >>> -- > >>> Dan Stromberg > >>> > >>> _______________________________________________ > >>> Beginners mailing list > >>> Beginners at haskell.org > >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > >>> > >> > >> > >> > >> -- > >> Department of Geography > >> State University of New York at Buffalo > >> > >> jykang22 at gmail.com > >> > >> Jeon-Young Kang > >> > >> _______________________________________________ > >> Beginners mailing list > >> Beginners at haskell.org > >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > >> > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Dan Stromberg -------------- next part -------------- An HTML attachment was scrubbed... URL: From jykang22 at gmail.com Sun Nov 22 01:03:08 2015 From: jykang22 at gmail.com (Jeon-Young Kang) Date: Sat, 21 Nov 2015 20:03:08 -0500 Subject: [Haskell-beginners] Warning: Tab Character In-Reply-To: References: Message-ID: Thanks! I figured out. On Sat, Nov 21, 2015 at 7:44 PM, Dan Stromberg wrote: > > I believe the first version of make required tabs, but some subsequent > versions have relaxed that requirement to make things easier. > > Here's an example on a Linux Mint system (the 20's are of course spaces) : > $ od -cx < Makefile > cmd output started 2015 Sat Nov 21 04:39:47 PM PST > 0000000 \n g o : \n . / t \n \n > 670a 3a6f 200a 2020 2e20 742f 0a0a > 0000016 > above cmd output done 2015 Sat Nov 21 04:39:47 PM PST > dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 > > $ make > cmd output started 2015 Sat Nov 21 04:39:48 PM PST > Makefile:3: *** missing separator. Stop. > above cmd output done 2015 Sat Nov 21 04:39:48 PM PST > dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 > > $ make --version > cmd output started 2015 Sat Nov 21 04:39:53 PM PST > GNU Make 3.81 > Copyright (C) 2006 Free Software Foundation, Inc. > This is free software; see the source for copying conditions. > There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A > PARTICULAR PURPOSE. > > This program built for i686-pc-linux-gnu > above cmd output done 2015 Sat Nov 21 04:39:53 PM PST > dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 > > > I'll add that vim's Makefile syntax highlighting puts the space-indented > line in red, suggesting an error. Changing the spaces to a single tab > makes the red go away. > > HTH > > On Sat, Nov 21, 2015 at 3:34 PM, Thomas Jakway wrote: > >> Why would make require tabs...? >> Admittedly it's been a long time since I've written any makefiles by hand >> but I always use spaces instead of tabs and have never had any problems. >> >> On Nov 21, 2015 6:01 PM, David Moberg wrote: >> > >> > Have you found "soft tabs"? That option will make TextMate use spaces >> instead of tab characters. Read 4.11 "Using Spaces Instead of Tabs" in Dan >> Strombergs link for instrucitons. >> > >> > 2015-11-21 21:36 GMT+01:00 Jeon-Young Kang : >> >> >> >> I've tried to choose "instead of spaces". But there is no option of >> mine (Textmate 2 beta). >> >> >> >> On Sat, Nov 21, 2015 at 3:14 PM, Dan Stromberg >> wrote: >> >>> >> >>> >> >>> Perhaps enable soft tabs? >> >>> https://manual.macromates.com/en/working_with_text >> >>> >> >>> This is an issue in Python too (at least from PEP8's perspective) - >> but note that many "make" programs require tabs instead of spaces. >> >>> >> >>> On Sat, Nov 21, 2015 at 11:13 AM, Jeon-Young Kang >> wrote: >> >>>> >> >>>> Hello everyone. >> >>>> >> >>>> >> >>>> I am a newbie of Haskell, using Textmate on mac. >> >>>> >> >>>> >> >>>> I got the following warning. How can I fix it? >> >>>> >> >>>> >> >>>> Warning: >> >>>> >> >>>> Tab character >> >>>> >> >>>> Ok, modules loaded: Main. >> >>>> >> >>>> >> >>>> >> >>>> Sincerely, >> >>>> Young >> >>>> >> >>>> _______________________________________________ >> >>>> Beginners mailing list >> >>>> Beginners at haskell.org >> >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >>>> >> >>> >> >>> >> >>> >> >>> -- >> >>> Dan Stromberg >> >>> >> >>> _______________________________________________ >> >>> Beginners mailing list >> >>> Beginners at haskell.org >> >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >>> >> >> >> >> >> >> >> >> -- >> >> Department of Geography >> >> State University of New York at Buffalo >> >> >> >> jykang22 at gmail.com >> >> >> >> Jeon-Young Kang >> >> >> >> _______________________________________________ >> >> Beginners mailing list >> >> Beginners at haskell.org >> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> >> > >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > > > -- > Dan Stromberg > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Department of Geography State University of New York at Buffalo jykang22 at gmail.com Jeon-Young Kang -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjakway at nyu.edu Sun Nov 22 01:22:04 2015 From: tjakway at nyu.edu (Thomas Jakway) Date: Sat, 21 Nov 2015 20:22:04 -0500 Subject: [Haskell-beginners] Warning: Tab Character In-Reply-To: Message-ID: <66118521-5ef8-4d50-b8dc-d65a38dd9620@email.android.com> Huh, cool. I had no idea. Thanks! On Nov 21, 2015 7:44 PM, Dan Stromberg wrote: > > > I believe the first version of make required tabs, but some subsequent versions have relaxed that requirement to make things easier. > > Here's an example on a Linux Mint system (the 20's are of course spaces) : > $ od -cx < Makefile > cmd output started 2015 Sat Nov 21 04:39:47 PM PST > 0000000? \n?? g?? o?? :? \n?????????????????? .?? /?? t? \n? \n > ?????????? 670a??? 3a6f??? 200a??? 2020??? 2e20??? 742f??? 0a0a > 0000016 > above cmd output done??? 2015 Sat Nov 21 04:39:47 PM PST > dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 > > $ make > cmd output started 2015 Sat Nov 21 04:39:48 PM PST > Makefile:3: *** missing separator.? Stop. > above cmd output done??? 2015 Sat Nov 21 04:39:48 PM PST > dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 > > $ make --version > cmd output started 2015 Sat Nov 21 04:39:53 PM PST > GNU Make 3.81 > Copyright (C) 2006? Free Software Foundation, Inc. > This is free software; see the source for copying conditions. > There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A > PARTICULAR PURPOSE. > > This program built for i686-pc-linux-gnu > above cmd output done??? 2015 Sat Nov 21 04:39:53 PM PST > dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 > > > I'll add that vim's Makefile syntax highlighting puts the space-indented line in red, suggesting an error.? Changing the spaces to a single tab makes the red go away. > > HTH > > On Sat, Nov 21, 2015 at 3:34 PM, Thomas Jakway wrote: >> >> Why would make require tabs...? >> Admittedly it's been a long time since I've written any makefiles by hand but I always use spaces instead of tabs and have never had any problems. >> >> On Nov 21, 2015 6:01 PM, David Moberg wrote: >> > >> > Have you found "soft tabs"? That option will make?TextMate use spaces instead of tab characters. Read?4.11 "Using Spaces Instead of Tabs" in Dan Strombergs link for instrucitons. >> > >> > 2015-11-21 21:36 GMT+01:00 Jeon-Young Kang : >> >> >> >> I've tried to choose "instead of spaces". But there is no option of mine (Textmate 2 beta). >> >> >> >> On Sat, Nov 21, 2015 at 3:14 PM, Dan Stromberg wrote: >> >>> >> >>> >> >>> Perhaps enable soft tabs? >> >>> https://manual.macromates.com/en/working_with_text >> >>> >> >>> This is an issue in Python too (at least from PEP8's perspective) - but note that many "make" programs require tabs instead of spaces. >> >>> >> >>> On Sat, Nov 21, 2015 at 11:13 AM, Jeon-Young Kang wrote: >> >>>> >> >>>> Hello everyone. >> >>>> >> >>>> >> >>>> I am a newbie of Haskell, using Textmate on mac. >> >>>> >> >>>> >> >>>> I got the following warning. How can I fix it? >> >>>> >> >>>> >> >>>> Warning: >> >>>> >> >>>> ? ? Tab character >> >>>> >> >>>> Ok, modules loaded: Main. >> >>>> >> >>>> >> >>>> >> >>>> Sincerely, >> >>>> Young >> >>>> >> >>>> _______________________________________________ >> >>>> Beginners mailing list >> >>>> Beginners at haskell.org >> >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >>>> >> >>> >> >>> >> >>> >> >>> -- >> >>> Dan Stromberg >> >>> >> >>> _______________________________________________ >> >>> Beginners mailing list >> >>> Beginners at haskell.org >> >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >>> >> >> >> >> >> >> >> >> -- >> >> Department of Geography >> >> State University of New York at Buffalo >> >> >> >> jykang22 at gmail.com >> >> ? >> >> Jeon-Young Kang >> >> >> >> _______________________________________________ >> >> Beginners mailing list >> >> Beginners at haskell.org >> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> >> > >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > > -- > Dan Stromberg From ky3 at atamo.com Sun Nov 22 03:52:13 2015 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Sun, 22 Nov 2015 10:52:13 +0700 Subject: [Haskell-beginners] help with type error in a wxHaskell program In-Reply-To: References: Message-ID: On Sat, Nov 21, 2015 at 8:28 PM, Jason J. Corso wrote: > But, I get a type error that I do not understand > > Couldn't match expected type ?IO (Window a0)? > with actual type ?[Prop (Frame ())] -> IO (Frame ())? > Probable cause: ?frame? is applied to too few arguments > This is a consequence of the line "f <- frame" in gui :: IO () gui = do f <- frame let s = map (\t -> staticText f [text := show t]) [1..10] set f [layout := margin 10 ( row 2 $ map (\x -> (widget x)) s)] I have no experience at all with wxHaskell. But for the sake of forward motion, substituting with "f <- frame []" should work. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjcorso at eecs.umich.edu Sun Nov 22 11:37:02 2015 From: jjcorso at eecs.umich.edu (Jason J. Corso) Date: Sun, 22 Nov 2015 06:37:02 -0500 Subject: [Haskell-beginners] help with type error in a wxHaskell program In-Reply-To: References: Message-ID: Thank you both for the help. There was another mistake after this piece. The let s = map... led to a [IO (StaticText())] and it had to be changed as below. The below code works. Thanks again. module Main where import Graphics.UI.WX main :: IO () main = start gui gui :: IO () gui = do f <- frame [text := "First Fix!"] ss <- mapM (\t -> staticText f [text := show t]) [1..10] set f [layout := margin 10 ( row 2 $ map (\x -> (widget x)) ss)] Jason On Sat, Nov 21, 2015 at 10:52 PM, Kim-Ee Yeoh wrote: > > On Sat, Nov 21, 2015 at 8:28 PM, Jason J. Corso > wrote: >> >> But, I get a type error that I do not understand >> >> Couldn't match expected type ?IO (Window a0)? >> with actual type ?[Prop (Frame ())] -> IO (Frame ())? >> Probable cause: ?frame? is applied to too few arguments > > > This is a consequence of the line "f <- frame" in > > gui :: IO () > gui = do > f <- frame > let s = map (\t -> staticText f [text := show t]) [1..10] > set f [layout := margin 10 ( row 2 $ map (\x -> (widget x)) s)] > > I have no experience at all with wxHaskell. But for the sake of forward > motion, substituting with "f <- frame []" should work. > > -- Kim-Ee > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From fgutiers2002 at yahoo.com Mon Nov 23 23:55:40 2015 From: fgutiers2002 at yahoo.com (Francisco Gutierrez) Date: Mon, 23 Nov 2015 23:55:40 +0000 (UTC) Subject: [Haskell-beginners] Beginners Digest, Vol 89, Issue 38 How to define a simple function In-Reply-To: References: Message-ID: <1315983120.9650814.1448322940910.JavaMail.yahoo@mail.yahoo.com> Dear sirs:I am defining a function halve, that breaks a list in two halfs. But I always get an error. Below is my code. What am I doing wrong?Thanks!halve xs = [take (floor (longitud/2)), drop (floor (longitud/2))]? where longitud = length xs From: "beginners-request at haskell.org" To: beginners at haskell.org Sent: Saturday, November 21, 2015 8:21 PM Subject: Beginners Digest, Vol 89, Issue 38 Send Beginners mailing list submissions to ??? beginners at haskell.org To subscribe or unsubscribe via the World Wide Web, visit ??? http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to ??? beginners-request at haskell.org You can reach the person managing the list at ??? beginners-owner at haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: ? 1. Re:? Warning: Tab Character (Dan Stromberg) ? 2. Re:? Warning: Tab Character (Jeon-Young Kang) ? 3. Re:? Warning: Tab Character (Thomas Jakway) ---------------------------------------------------------------------- Message: 1 Date: Sat, 21 Nov 2015 16:44:21 -0800 From: Dan Stromberg To: The Haskell-Beginners Mailing List - Discussion of primarily ??? beginner-level topics related to Haskell Subject: Re: [Haskell-beginners] Warning: Tab Character Message-ID: ??? Content-Type: text/plain; charset="utf-8" I believe the first version of make required tabs, but some subsequent versions have relaxed that requirement to make things easier. Here's an example on a Linux Mint system (the 20's are of course spaces) : $ od -cx < Makefile cmd output started 2015 Sat Nov 21 04:39:47 PM PST 0000000? \n? g? o? :? \n? ? ? ? ? ? ? ? ? .? /? t? \n? \n ? ? ? ? ? 670a? ? 3a6f? ? 200a? ? 2020? ? 2e20? ? 742f? ? 0a0a 0000016 above cmd output done? ? 2015 Sat Nov 21 04:39:47 PM PST dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 $ make cmd output started 2015 Sat Nov 21 04:39:48 PM PST Makefile:3: *** missing separator.? Stop. above cmd output done? ? 2015 Sat Nov 21 04:39:48 PM PST dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 $ make --version cmd output started 2015 Sat Nov 21 04:39:53 PM PST GNU Make 3.81 Copyright (C) 2006? Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This program built for i686-pc-linux-gnu above cmd output done? ? 2015 Sat Nov 21 04:39:53 PM PST dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 I'll add that vim's Makefile syntax highlighting puts the space-indented line in red, suggesting an error.? Changing the spaces to a single tab makes the red go away. HTH On Sat, Nov 21, 2015 at 3:34 PM, Thomas Jakway wrote: > Why would make require tabs...? > Admittedly it's been a long time since I've written any makefiles by hand > but I always use spaces instead of tabs and have never had any problems. > > On Nov 21, 2015 6:01 PM, David Moberg wrote: > > > > Have you found "soft tabs"? That option will make TextMate use spaces > instead of tab characters. Read 4.11 "Using Spaces Instead of Tabs" in Dan > Strombergs link for instrucitons. > > > > 2015-11-21 21:36 GMT+01:00 Jeon-Young Kang : > >> > >> I've tried to choose "instead of spaces". But there is no option of > mine (Textmate 2 beta). > >> > >> On Sat, Nov 21, 2015 at 3:14 PM, Dan Stromberg > wrote: > >>> > >>> > >>> Perhaps enable soft tabs? > >>> https://manual.macromates.com/en/working_with_text > >>> > >>> This is an issue in Python too (at least from PEP8's perspective) - > but note that many "make" programs require tabs instead of spaces. > >>> > >>> On Sat, Nov 21, 2015 at 11:13 AM, Jeon-Young Kang > wrote: > >>>> > >>>> Hello everyone. > >>>> > >>>> > >>>> I am a newbie of Haskell, using Textmate on mac. > >>>> > >>>> > >>>> I got the following warning. How can I fix it? > >>>> > >>>> > >>>> Warning: > >>>> > >>>>? ? Tab character > >>>> > >>>> Ok, modules loaded: Main. > >>>> > >>>> > >>>> > >>>> Sincerely, > >>>> Young > >>>> > >>>> _______________________________________________ > >>>> Beginners mailing list > >>>> Beginners at haskell.org > >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > >>>> > >>> > >>> > >>> > >>> -- > >>> Dan Stromberg > >>> > >>> _______________________________________________ > >>> Beginners mailing list > >>> Beginners at haskell.org > >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > >>> > >> > >> > >> > >> -- > >> Department of Geography > >> State University of New York at Buffalo > >> > >> jykang22 at gmail.com > >> > >> Jeon-Young Kang > >> > >> _______________________________________________ > >> Beginners mailing list > >> Beginners at haskell.org > >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > >> > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Dan Stromberg -------------- next part -------------- An HTML attachment was scrubbed... URL: ------------------------------ Message: 2 Date: Sat, 21 Nov 2015 20:03:08 -0500 From: Jeon-Young Kang To: The Haskell-Beginners Mailing List - Discussion of primarily ??? beginner-level topics related to Haskell Subject: Re: [Haskell-beginners] Warning: Tab Character Message-ID: ??? Content-Type: text/plain; charset="utf-8" Thanks! I figured out. On Sat, Nov 21, 2015 at 7:44 PM, Dan Stromberg wrote: > > I believe the first version of make required tabs, but some subsequent > versions have relaxed that requirement to make things easier. > > Here's an example on a Linux Mint system (the 20's are of course spaces) : > $ od -cx < Makefile > cmd output started 2015 Sat Nov 21 04:39:47 PM PST > 0000000? \n? g? o? :? \n? ? ? ? ? ? ? ? ? .? /? t? \n? \n >? ? ? ? ? ? 670a? ? 3a6f? ? 200a? ? 2020? ? 2e20? ? 742f? ? 0a0a > 0000016 > above cmd output done? ? 2015 Sat Nov 21 04:39:47 PM PST > dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 > > $ make > cmd output started 2015 Sat Nov 21 04:39:48 PM PST > Makefile:3: *** missing separator.? Stop. > above cmd output done? ? 2015 Sat Nov 21 04:39:48 PM PST > dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 > > $ make --version > cmd output started 2015 Sat Nov 21 04:39:53 PM PST > GNU Make 3.81 > Copyright (C) 2006? Free Software Foundation, Inc. > This is free software; see the source for copying conditions. > There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A > PARTICULAR PURPOSE. > > This program built for i686-pc-linux-gnu > above cmd output done? ? 2015 Sat Nov 21 04:39:53 PM PST > dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 > > > I'll add that vim's Makefile syntax highlighting puts the space-indented > line in red, suggesting an error.? Changing the spaces to a single tab > makes the red go away. > > HTH > > On Sat, Nov 21, 2015 at 3:34 PM, Thomas Jakway wrote: > >> Why would make require tabs...? >> Admittedly it's been a long time since I've written any makefiles by hand >> but I always use spaces instead of tabs and have never had any problems. >> >> On Nov 21, 2015 6:01 PM, David Moberg wrote: >> > >> > Have you found "soft tabs"? That option will make TextMate use spaces >> instead of tab characters. Read 4.11 "Using Spaces Instead of Tabs" in Dan >> Strombergs link for instrucitons. >> > >> > 2015-11-21 21:36 GMT+01:00 Jeon-Young Kang : >> >> >> >> I've tried to choose "instead of spaces". But there is no option of >> mine (Textmate 2 beta). >> >> >> >> On Sat, Nov 21, 2015 at 3:14 PM, Dan Stromberg >> wrote: >> >>> >> >>> >> >>> Perhaps enable soft tabs? >> >>> https://manual.macromates.com/en/working_with_text >> >>> >> >>> This is an issue in Python too (at least from PEP8's perspective) - >> but note that many "make" programs require tabs instead of spaces. >> >>> >> >>> On Sat, Nov 21, 2015 at 11:13 AM, Jeon-Young Kang >> wrote: >> >>>> >> >>>> Hello everyone. >> >>>> >> >>>> >> >>>> I am a newbie of Haskell, using Textmate on mac. >> >>>> >> >>>> >> >>>> I got the following warning. How can I fix it? >> >>>> >> >>>> >> >>>> Warning: >> >>>> >> >>>>? ? Tab character >> >>>> >> >>>> Ok, modules loaded: Main. >> >>>> >> >>>> >> >>>> >> >>>> Sincerely, >> >>>> Young >> >>>> >> >>>> _______________________________________________ >> >>>> Beginners mailing list >> >>>> Beginners at haskell.org >> >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >>>> >> >>> >> >>> >> >>> >> >>> -- >> >>> Dan Stromberg >> >>> >> >>> _______________________________________________ >> >>> Beginners mailing list >> >>> Beginners at haskell.org >> >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >>> >> >> >> >> >> >> >> >> -- >> >> Department of Geography >> >> State University of New York at Buffalo >> >> >> >> jykang22 at gmail.com >> >> >> >> Jeon-Young Kang >> >> >> >> _______________________________________________ >> >> Beginners mailing list >> >> Beginners at haskell.org >> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> >> > >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > > > -- > Dan Stromberg > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Department of Geography State University of New York at Buffalo jykang22 at gmail.com Jeon-Young Kang -------------- next part -------------- An HTML attachment was scrubbed... URL: ------------------------------ Message: 3 Date: Sat, 21 Nov 2015 20:22:04 -0500 From: Thomas Jakway To: The Haskell-Beginners Mailing List - Discussion of primarily ??? beginner-level topics related to Haskell Subject: Re: [Haskell-beginners] Warning: Tab Character Message-ID: <66118521-5ef8-4d50-b8dc-d65a38dd9620 at email.android.com> Content-Type: text/plain; charset=utf-8 Huh, cool.? I had no idea.? Thanks! On Nov 21, 2015 7:44 PM, Dan Stromberg wrote: > > > I believe the first version of make required tabs, but some subsequent versions have relaxed that requirement to make things easier. > > Here's an example on a Linux Mint system (the 20's are of course spaces) : > $ od -cx < Makefile > cmd output started 2015 Sat Nov 21 04:39:47 PM PST > 0000000? \n?? g?? o?? :? \n?????????????????? .?? /?? t? \n? \n > ?????????? 670a??? 3a6f??? 200a??? 2020??? 2e20??? 742f??? 0a0a > 0000016 > above cmd output done??? 2015 Sat Nov 21 04:39:47 PM PST > dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 > > $ make > cmd output started 2015 Sat Nov 21 04:39:48 PM PST > Makefile:3: *** missing separator.? Stop. > above cmd output done??? 2015 Sat Nov 21 04:39:48 PM PST > dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 > > $ make --version > cmd output started 2015 Sat Nov 21 04:39:53 PM PST > GNU Make 3.81 > Copyright (C) 2006? Free Software Foundation, Inc. > This is free software; see the source for copying conditions. > There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A > PARTICULAR PURPOSE. > > This program built for i686-pc-linux-gnu > above cmd output done??? 2015 Sat Nov 21 04:39:53 PM PST > dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 > > > I'll add that vim's Makefile syntax highlighting puts the space-indented line in red, suggesting an error.? Changing the spaces to a single tab makes the red go away. > > HTH > > On Sat, Nov 21, 2015 at 3:34 PM, Thomas Jakway wrote: >> >> Why would make require tabs...? >> Admittedly it's been a long time since I've written any makefiles by hand but I always use spaces instead of tabs and have never had any problems. >> >> On Nov 21, 2015 6:01 PM, David Moberg wrote: >> > >> > Have you found "soft tabs"? That option will make?TextMate use spaces instead of tab characters. Read?4.11 "Using Spaces Instead of Tabs" in Dan Strombergs link for instrucitons. >> > >> > 2015-11-21 21:36 GMT+01:00 Jeon-Young Kang : >> >> >> >> I've tried to choose "instead of spaces". But there is no option of mine (Textmate 2 beta). >> >> >> >> On Sat, Nov 21, 2015 at 3:14 PM, Dan Stromberg wrote: >> >>> >> >>> >> >>> Perhaps enable soft tabs? >> >>> https://manual.macromates.com/en/working_with_text >> >>> >> >>> This is an issue in Python too (at least from PEP8's perspective) - but note that many "make" programs require tabs instead of spaces. >> >>> >> >>> On Sat, Nov 21, 2015 at 11:13 AM, Jeon-Young Kang wrote: >> >>>> >> >>>> Hello everyone. >> >>>> >> >>>> >> >>>> I am a newbie of Haskell, using Textmate on mac. >> >>>> >> >>>> >> >>>> I got the following warning. How can I fix it? >> >>>> >> >>>> >> >>>> Warning: >> >>>> >> >>>> ? ? Tab character >> >>>> >> >>>> Ok, modules loaded: Main. >> >>>> >> >>>> >> >>>> >> >>>> Sincerely, >> >>>> Young >> >>>> >> >>>> _______________________________________________ >> >>>> Beginners mailing list >> >>>> Beginners at haskell.org >> >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >>>> >> >>> >> >>> >> >>> >> >>> -- >> >>> Dan Stromberg >> >>> >> >>> _______________________________________________ >> >>> Beginners mailing list >> >>> Beginners at haskell.org >> >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >>> >> >> >> >> >> >> >> >> -- >> >> Department of Geography >> >> State University of New York at Buffalo >> >> >> >> jykang22 at gmail.com >> >> ? >> >> Jeon-Young Kang >> >> >> >> _______________________________________________ >> >> Beginners mailing list >> >> Beginners at haskell.org >> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> >> > >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > > -- > Dan Stromberg ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 89, Issue 38 ***************************************** -------------- next part -------------- An HTML attachment was scrubbed... URL: From matthewjwilliams101 at gmail.com Tue Nov 24 04:29:16 2015 From: matthewjwilliams101 at gmail.com (MJ Williams) Date: Tue, 24 Nov 2015 04:29:16 +0000 Subject: [Haskell-beginners] Beginners Digest, Vol 89, Issue 38 How to define a simple function In-Reply-To: <1315983120.9650814.1448322940910.JavaMail.yahoo@mail.yahoo.com> References: <1315983120.9650814.1448322940910.JavaMail.yahoo@mail.yahoo.com> Message-ID: In short, your types do not match in your calculation of the half of the length of the list. According to GHCI length :: [a] -> Int (/) :: Fractional a => a -> a -> a floor :: (Integral b, RealFrac a) => a -> b Can you see how you might run into problems with this mixed bag of types? The only instance where you might find type compatibility between above types would be if you were passing a value of type `Int' to a function that accepted values of type `Integral'. `Int', if you like, is a subset of `Integral' A simple solution would be to replace `/' with `div' (`div :: Integral a => a -> a -> a'). Thus, your functionwould look something like halve :: [a] -> [[a], [a]] halve xs = [take longitud xs, drop longitud xs] where longitud = div (length xs) 2 Hope that helps, and don't hesitate to come back with more questions. Matthew On 23/11/2015, Francisco Gutierrez wrote: > Dear sirs:I am defining a function halve, that breaks a list in two halfs. > But I always get an error. Below is my code. What am I doing > wrong?Thanks!halve xs = [take (floor (longitud/2)), drop (floor > (longitud/2))]? where longitud = length xs > > > From: "beginners-request at haskell.org" > To: beginners at haskell.org > Sent: Saturday, November 21, 2015 8:21 PM > Subject: Beginners Digest, Vol 89, Issue 38 > > Send Beginners mailing list submissions to > ??? beginners at haskell.org > > To subscribe or unsubscribe via the World Wide Web, visit > ??? http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > or, via email, send a message with subject or body 'help' to > ??? beginners-request at haskell.org > > You can reach the person managing the list at > ??? beginners-owner at haskell.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Beginners digest..." > > > Today's Topics: > > ? 1. Re:? Warning: Tab Character (Dan Stromberg) > ? 2. Re:? Warning: Tab Character (Jeon-Young Kang) > ? 3. Re:? Warning: Tab Character (Thomas Jakway) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Sat, 21 Nov 2015 16:44:21 -0800 > From: Dan Stromberg > To: The Haskell-Beginners Mailing List - Discussion of primarily > ??? beginner-level topics related to Haskell > Subject: Re: [Haskell-beginners] Warning: Tab Character > Message-ID: > ??? > Content-Type: text/plain; charset="utf-8" > > I believe the first version of make required tabs, but some subsequent > versions have relaxed that requirement to make things easier. > > Here's an example on a Linux Mint system (the 20's are of course spaces) : > $ od -cx < Makefile > cmd output started 2015 Sat Nov 21 04:39:47 PM PST > 0000000? \n? g? o? :? \n? ? ? ? ? ? ? ? ? .? /? t? \n? \n > ? ? ? ? ? 670a? ? 3a6f? ? 200a? ? 2020? ? 2e20? ? 742f? ? 0a0a > 0000016 > above cmd output done? ? 2015 Sat Nov 21 04:39:47 PM PST > dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 > > $ make > cmd output started 2015 Sat Nov 21 04:39:48 PM PST > Makefile:3: *** missing separator.? Stop. > above cmd output done? ? 2015 Sat Nov 21 04:39:48 PM PST > dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 > > $ make --version > cmd output started 2015 Sat Nov 21 04:39:53 PM PST > GNU Make 3.81 > Copyright (C) 2006? Free Software Foundation, Inc. > This is free software; see the source for copying conditions. > There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A > PARTICULAR PURPOSE. > > This program built for i686-pc-linux-gnu > above cmd output done? ? 2015 Sat Nov 21 04:39:53 PM PST > dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 > > > I'll add that vim's Makefile syntax highlighting puts the space-indented > line in red, suggesting an error.? Changing the spaces to a single tab > makes the red go away. > > HTH > > On Sat, Nov 21, 2015 at 3:34 PM, Thomas Jakway wrote: > >> Why would make require tabs...? >> Admittedly it's been a long time since I've written any makefiles by hand >> but I always use spaces instead of tabs and have never had any problems. >> >> On Nov 21, 2015 6:01 PM, David Moberg wrote: >> > >> > Have you found "soft tabs"? That option will make TextMate use spaces >> instead of tab characters. Read 4.11 "Using Spaces Instead of Tabs" in >> Dan >> Strombergs link for instrucitons. >> > >> > 2015-11-21 21:36 GMT+01:00 Jeon-Young Kang : >> >> >> >> I've tried to choose "instead of spaces". But there is no option of >> mine (Textmate 2 beta). >> >> >> >> On Sat, Nov 21, 2015 at 3:14 PM, Dan Stromberg >> wrote: >> >>> >> >>> >> >>> Perhaps enable soft tabs? >> >>> https://manual.macromates.com/en/working_with_text >> >>> >> >>> This is an issue in Python too (at least from PEP8's perspective) - >> but note that many "make" programs require tabs instead of spaces. >> >>> >> >>> On Sat, Nov 21, 2015 at 11:13 AM, Jeon-Young Kang >> >>> >> wrote: >> >>>> >> >>>> Hello everyone. >> >>>> >> >>>> >> >>>> I am a newbie of Haskell, using Textmate on mac. >> >>>> >> >>>> >> >>>> I got the following warning. How can I fix it? >> >>>> >> >>>> >> >>>> Warning: >> >>>> >> >>>>? ? Tab character >> >>>> >> >>>> Ok, modules loaded: Main. >> >>>> >> >>>> >> >>>> >> >>>> Sincerely, >> >>>> Young >> >>>> >> >>>> _______________________________________________ >> >>>> Beginners mailing list >> >>>> Beginners at haskell.org >> >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >>>> >> >>> >> >>> >> >>> >> >>> -- >> >>> Dan Stromberg >> >>> >> >>> _______________________________________________ >> >>> Beginners mailing list >> >>> Beginners at haskell.org >> >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >>> >> >> >> >> >> >> >> >> -- >> >> Department of Geography >> >> State University of New York at Buffalo >> >> >> >> jykang22 at gmail.com >> >> >> >> Jeon-Young Kang >> >> >> >> _______________________________________________ >> >> Beginners mailing list >> >> Beginners at haskell.org >> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> >> > >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > > > -- > Dan Stromberg > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > > > ------------------------------ > > Message: 2 > Date: Sat, 21 Nov 2015 20:03:08 -0500 > From: Jeon-Young Kang > To: The Haskell-Beginners Mailing List - Discussion of primarily > ??? beginner-level topics related to Haskell > Subject: Re: [Haskell-beginners] Warning: Tab Character > Message-ID: > ??? > Content-Type: text/plain; charset="utf-8" > > Thanks! I figured out. > > On Sat, Nov 21, 2015 at 7:44 PM, Dan Stromberg wrote: > >> >> I believe the first version of make required tabs, but some subsequent >> versions have relaxed that requirement to make things easier. >> >> Here's an example on a Linux Mint system (the 20's are of course spaces) >> : >> $ od -cx < Makefile >> cmd output started 2015 Sat Nov 21 04:39:47 PM PST >> 0000000? \n? g? o? :? \n? ? ? ? ? ? ? ? ? .? /? t? \n? \n >>? ? ? ? ? ? 670a? ? 3a6f? ? 200a? ? 2020? ? 2e20? ? 742f? ? 0a0a >> 0000016 >> above cmd output done? ? 2015 Sat Nov 21 04:39:47 PM PST >> dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 >> >> $ make >> cmd output started 2015 Sat Nov 21 04:39:48 PM PST >> Makefile:3: *** missing separator.? Stop. >> above cmd output done? ? 2015 Sat Nov 21 04:39:48 PM PST >> dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 >> >> $ make --version >> cmd output started 2015 Sat Nov 21 04:39:53 PM PST >> GNU Make 3.81 >> Copyright (C) 2006? Free Software Foundation, Inc. >> This is free software; see the source for copying conditions. >> There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A >> PARTICULAR PURPOSE. >> >> This program built for i686-pc-linux-gnu >> above cmd output done? ? 2015 Sat Nov 21 04:39:53 PM PST >> dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 >> >> >> I'll add that vim's Makefile syntax highlighting puts the space-indented >> line in red, suggesting an error.? Changing the spaces to a single tab >> makes the red go away. >> >> HTH >> >> On Sat, Nov 21, 2015 at 3:34 PM, Thomas Jakway wrote: >> >>> Why would make require tabs...? >>> Admittedly it's been a long time since I've written any makefiles by >>> hand >>> but I always use spaces instead of tabs and have never had any problems. >>> >>> On Nov 21, 2015 6:01 PM, David Moberg wrote: >>> > >>> > Have you found "soft tabs"? That option will make TextMate use spaces >>> instead of tab characters. Read 4.11 "Using Spaces Instead of Tabs" in >>> Dan >>> Strombergs link for instrucitons. >>> > >>> > 2015-11-21 21:36 GMT+01:00 Jeon-Young Kang : >>> >> >>> >> I've tried to choose "instead of spaces". But there is no option of >>> mine (Textmate 2 beta). >>> >> >>> >> On Sat, Nov 21, 2015 at 3:14 PM, Dan Stromberg >>> wrote: >>> >>> >>> >>> >>> >>> Perhaps enable soft tabs? >>> >>> https://manual.macromates.com/en/working_with_text >>> >>> >>> >>> This is an issue in Python too (at least from PEP8's perspective) - >>> but note that many "make" programs require tabs instead of spaces. >>> >>> >>> >>> On Sat, Nov 21, 2015 at 11:13 AM, Jeon-Young Kang >>> >>> >>> wrote: >>> >>>> >>> >>>> Hello everyone. >>> >>>> >>> >>>> >>> >>>> I am a newbie of Haskell, using Textmate on mac. >>> >>>> >>> >>>> >>> >>>> I got the following warning. How can I fix it? >>> >>>> >>> >>>> >>> >>>> Warning: >>> >>>> >>> >>>>? ? Tab character >>> >>>> >>> >>>> Ok, modules loaded: Main. >>> >>>> >>> >>>> >>> >>>> >>> >>>> Sincerely, >>> >>>> Young >>> >>>> >>> >>>> _______________________________________________ >>> >>>> Beginners mailing list >>> >>>> Beginners at haskell.org >>> >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>>> >>> >>> >>> >>> >>> >>> >>> >>> -- >>> >>> Dan Stromberg >>> >>> >>> >>> _______________________________________________ >>> >>> Beginners mailing list >>> >>> Beginners at haskell.org >>> >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >>> >> >>> >> >>> >> >>> >> -- >>> >> Department of Geography >>> >> State University of New York at Buffalo >>> >> >>> >> jykang22 at gmail.com >>> >> >>> >> Jeon-Young Kang >>> >> >>> >> _______________________________________________ >>> >> Beginners mailing list >>> >> Beginners at haskell.org >>> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >> >>> > >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >> >> >> >> -- >> Dan Stromberg >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > > -- > Department of Geography > State University of New York at Buffalo > > jykang22 at gmail.com > > Jeon-Young Kang > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > > > ------------------------------ > > Message: 3 > Date: Sat, 21 Nov 2015 20:22:04 -0500 > From: Thomas Jakway > To: The Haskell-Beginners Mailing List - Discussion of primarily > ??? beginner-level topics related to Haskell > Subject: Re: [Haskell-beginners] Warning: Tab Character > Message-ID: <66118521-5ef8-4d50-b8dc-d65a38dd9620 at email.android.com> > Content-Type: text/plain; charset=utf-8 > > Huh, cool.? I had no idea.? Thanks! > > On Nov 21, 2015 7:44 PM, Dan Stromberg wrote: >> >> >> I believe the first version of make required tabs, but some subsequent >> versions have relaxed that requirement to make things easier. >> >> Here's an example on a Linux Mint system (the 20's are of course spaces) >> : >> $ od -cx < Makefile >> cmd output started 2015 Sat Nov 21 04:39:47 PM PST >> 0000000? \n?? g?? o?? :? \n?????????????????? .?? /?? t? \n? \n >> ?????????? 670a??? 3a6f??? 200a??? 2020??? 2e20??? 742f??? 0a0a >> 0000016 >> above cmd output done??? 2015 Sat Nov 21 04:39:47 PM PST >> dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 >> >> $ make >> cmd output started 2015 Sat Nov 21 04:39:48 PM PST >> Makefile:3: *** missing separator.? Stop. >> above cmd output done??? 2015 Sat Nov 21 04:39:48 PM PST >> dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 >> >> $ make --version >> cmd output started 2015 Sat Nov 21 04:39:53 PM PST >> GNU Make 3.81 >> Copyright (C) 2006? Free Software Foundation, Inc. >> This is free software; see the source for copying conditions. >> There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A >> PARTICULAR PURPOSE. >> >> This program built for i686-pc-linux-gnu >> above cmd output done??? 2015 Sat Nov 21 04:39:53 PM PST >> dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 >> >> >> I'll add that vim's Makefile syntax highlighting puts the space-indented >> line in red, suggesting an error.? Changing the spaces to a single tab >> makes the red go away. >> >> HTH >> >> On Sat, Nov 21, 2015 at 3:34 PM, Thomas Jakway wrote: >>> >>> Why would make require tabs...? >>> Admittedly it's been a long time since I've written any makefiles by hand >>> but I always use spaces instead of tabs and have never had any problems. >>> >>> On Nov 21, 2015 6:01 PM, David Moberg wrote: >>> > >>> > Have you found "soft tabs"? That option will make?TextMate use spaces >>> > instead of tab characters. Read?4.11 "Using Spaces Instead of Tabs" in >>> > Dan Strombergs link for instrucitons. >>> > >>> > 2015-11-21 21:36 GMT+01:00 Jeon-Young Kang : >>> >> >>> >> I've tried to choose "instead of spaces". But there is no option of >>> >> mine (Textmate 2 beta). >>> >> >>> >> On Sat, Nov 21, 2015 at 3:14 PM, Dan Stromberg >>> >> wrote: >>> >>> >>> >>> >>> >>> Perhaps enable soft tabs? >>> >>> https://manual.macromates.com/en/working_with_text >>> >>> >>> >>> This is an issue in Python too (at least from PEP8's perspective) - >>> >>> but note that many "make" programs require tabs instead of spaces. >>> >>> >>> >>> On Sat, Nov 21, 2015 at 11:13 AM, Jeon-Young Kang >>> >>> wrote: >>> >>>> >>> >>>> Hello everyone. >>> >>>> >>> >>>> >>> >>>> I am a newbie of Haskell, using Textmate on mac. >>> >>>> >>> >>>> >>> >>>> I got the following warning. How can I fix it? >>> >>>> >>> >>>> >>> >>>> Warning: >>> >>>> >>> >>>> ? ? Tab character >>> >>>> >>> >>>> Ok, modules loaded: Main. >>> >>>> >>> >>>> >>> >>>> >>> >>>> Sincerely, >>> >>>> Young >>> >>>> >>> >>>> _______________________________________________ >>> >>>> Beginners mailing list >>> >>>> Beginners at haskell.org >>> >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>>> >>> >>> >>> >>> >>> >>> >>> >>> -- >>> >>> Dan Stromberg >>> >>> >>> >>> _______________________________________________ >>> >>> Beginners mailing list >>> >>> Beginners at haskell.org >>> >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >>> >> >>> >> >>> >> >>> >> -- >>> >> Department of Geography >>> >> State University of New York at Buffalo >>> >> >>> >> jykang22 at gmail.com >>> >> ? >>> >> Jeon-Young Kang >>> >> >>> >> _______________________________________________ >>> >> Beginners mailing list >>> >> Beginners at haskell.org >>> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >> >>> > >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> >> >> >> -- >> Dan Stromberg > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > ------------------------------ > > End of Beginners Digest, Vol 89, Issue 38 > ***************************************** > > > From gesh at gesh.uni.cx Tue Nov 24 08:08:00 2015 From: gesh at gesh.uni.cx (Gesh) Date: Tue, 24 Nov 2015 10:08:00 +0200 Subject: [Haskell-beginners] Beginners Digest, Vol 89, Issue 38 How to define a simple function In-Reply-To: References: <1315983120.9650814.1448322940910.JavaMail.yahoo@mail.yahoo.com> Message-ID: <2BA40A55-B61A-414F-86D8-216CC24B2827@gesh.uni.cx> On November 24, 2015 6:29:16 AM GMT+02:00, MJ Williams wrote: >In short, your types do not match in your calculation of the half of >the length of the list. According to GHCI > >length :: [a] -> Int >(/) :: Fractional a => a -> a -> a >floor :: (Integral b, RealFrac a) => a -> b > >Can you see how you might run into problems with this mixed bag of >types? > >The only instance where you might find type compatibility between >above types would be if you were passing a value of type `Int' to a >function that accepted values of type `Integral'. `Int', if you like, >is a subset of `Integral' > >A simple solution would be to replace `/' with `div' (`div :: Integral >a => a -> a -> a'). Thus, your functionwould look something like > >halve :: [a] -> [[a], [a]] >halve xs = [take longitud xs, drop longitud xs] > where > longitud = div (length xs) 2 > >Hope that helps, and don't hesitate to come back with more questions. > >Matthew > > >On 23/11/2015, Francisco Gutierrez wrote: >> Dear sirs:I am defining a function halve, that breaks a list in two >halfs. >> But I always get an error. Below is my code. What am I doing >> wrong?Thanks!halve xs = [take (floor (longitud/2)), drop (floor >> (longitud/2))]? where longitud = length xs >> >> >> From: "beginners-request at haskell.org" > >> To: beginners at haskell.org >> Sent: Saturday, November 21, 2015 8:21 PM >> Subject: Beginners Digest, Vol 89, Issue 38 >> >> Send Beginners mailing list submissions to >> ??? beginners at haskell.org >> >> To subscribe or unsubscribe via the World Wide Web, visit >> ??? http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> or, via email, send a message with subject or body 'help' to >> ??? beginners-request at haskell.org >> >> You can reach the person managing the list at >> ??? beginners-owner at haskell.org >> >> When replying, please edit your Subject line so it is more specific >> than "Re: Contents of Beginners digest..." >> >> >> Today's Topics: >> >> ? 1. Re:? Warning: Tab Character (Dan Stromberg) >> ? 2. Re:? Warning: Tab Character (Jeon-Young Kang) >> ? 3. Re:? Warning: Tab Character (Thomas Jakway) >> >> >> >---------------------------------------------------------------------- >> >> Message: 1 >> Date: Sat, 21 Nov 2015 16:44:21 -0800 >> From: Dan Stromberg >> To: The Haskell-Beginners Mailing List - Discussion of primarily >> ??? beginner-level topics related to Haskell >> Subject: Re: [Haskell-beginners] Warning: Tab Character >> Message-ID: >> ??? > >> Content-Type: text/plain; charset="utf-8" >> >> I believe the first version of make required tabs, but some >subsequent >> versions have relaxed that requirement to make things easier. >> >> Here's an example on a Linux Mint system (the 20's are of course >spaces) : >> $ od -cx < Makefile >> cmd output started 2015 Sat Nov 21 04:39:47 PM PST >> 0000000? \n? g? o? :? \n? ? ? ? ? ? ? ? ? .? /? t? \n? \n >> ? ? ? ? ? 670a? ? 3a6f? ? 200a? ? 2020? ? 2e20? ? 742f? ? 0a0a >> 0000016 >> above cmd output done? ? 2015 Sat Nov 21 04:39:47 PM PST >> dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 >> >> $ make >> cmd output started 2015 Sat Nov 21 04:39:48 PM PST >> Makefile:3: *** missing separator.? Stop. >> above cmd output done? ? 2015 Sat Nov 21 04:39:48 PM PST >> dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 >> >> $ make --version >> cmd output started 2015 Sat Nov 21 04:39:53 PM PST >> GNU Make 3.81 >> Copyright (C) 2006? Free Software Foundation, Inc. >> This is free software; see the source for copying conditions. >> There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A >> PARTICULAR PURPOSE. >> >> This program built for i686-pc-linux-gnu >> above cmd output done? ? 2015 Sat Nov 21 04:39:53 PM PST >> dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 >> >> >> I'll add that vim's Makefile syntax highlighting puts the >space-indented >> line in red, suggesting an error.? Changing the spaces to a single >tab >> makes the red go away. >> >> HTH >> >> On Sat, Nov 21, 2015 at 3:34 PM, Thomas Jakway >wrote: >> >>> Why would make require tabs...? >>> Admittedly it's been a long time since I've written any makefiles by >hand >>> but I always use spaces instead of tabs and have never had any >problems. >>> >>> On Nov 21, 2015 6:01 PM, David Moberg wrote: >>> > >>> > Have you found "soft tabs"? That option will make TextMate use >spaces >>> instead of tab characters. Read 4.11 "Using Spaces Instead of Tabs" >in >>> Dan >>> Strombergs link for instrucitons. >>> > >>> > 2015-11-21 21:36 GMT+01:00 Jeon-Young Kang : >>> >> >>> >> I've tried to choose "instead of spaces". But there is no option >of >>> mine (Textmate 2 beta). >>> >> >>> >> On Sat, Nov 21, 2015 at 3:14 PM, Dan Stromberg > >>> wrote: >>> >>> >>> >>> >>> >>> Perhaps enable soft tabs? >>> >>> https://manual.macromates.com/en/working_with_text >>> >>> >>> >>> This is an issue in Python too (at least from PEP8's >perspective) - >>> but note that many "make" programs require tabs instead of spaces. >>> >>> >>> >>> On Sat, Nov 21, 2015 at 11:13 AM, Jeon-Young Kang >>> >>> >>> wrote: >>> >>>> >>> >>>> Hello everyone. >>> >>>> >>> >>>> >>> >>>> I am a newbie of Haskell, using Textmate on mac. >>> >>>> >>> >>>> >>> >>>> I got the following warning. How can I fix it? >>> >>>> >>> >>>> >>> >>>> Warning: >>> >>>> >>> >>>>? ? Tab character >>> >>>> >>> >>>> Ok, modules loaded: Main. >>> >>>> >>> >>>> >>> >>>> >>> >>>> Sincerely, >>> >>>> Young >>> >>>> >>> >>>> _______________________________________________ >>> >>>> Beginners mailing list >>> >>>> Beginners at haskell.org >>> >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>>> >>> >>> >>> >>> >>> >>> >>> >>> -- >>> >>> Dan Stromberg >>> >>> >>> >>> _______________________________________________ >>> >>> Beginners mailing list >>> >>> Beginners at haskell.org >>> >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >>> >> >>> >> >>> >> >>> >> -- >>> >> Department of Geography >>> >> State University of New York at Buffalo >>> >> >>> >> jykang22 at gmail.com >>> >> >>> >> Jeon-Young Kang >>> >> >>> >> _______________________________________________ >>> >> Beginners mailing list >>> >> Beginners at haskell.org >>> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >> >>> > >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >> >> >> >> -- >> Dan Stromberg >> -------------- next part -------------- >> An HTML attachment was scrubbed... >> URL: >> > >> >> ------------------------------ >> >> Message: 2 >> Date: Sat, 21 Nov 2015 20:03:08 -0500 >> From: Jeon-Young Kang >> To: The Haskell-Beginners Mailing List - Discussion of primarily >> ??? beginner-level topics related to Haskell >> Subject: Re: [Haskell-beginners] Warning: Tab Character >> Message-ID: >> ??? > >> Content-Type: text/plain; charset="utf-8" >> >> Thanks! I figured out. >> >> On Sat, Nov 21, 2015 at 7:44 PM, Dan Stromberg >wrote: >> >>> >>> I believe the first version of make required tabs, but some >subsequent >>> versions have relaxed that requirement to make things easier. >>> >>> Here's an example on a Linux Mint system (the 20's are of course >spaces) >>> : >>> $ od -cx < Makefile >>> cmd output started 2015 Sat Nov 21 04:39:47 PM PST >>> 0000000? \n? g? o? :? \n? ? ? ? ? ? ? ? ? .? /? t? \n? \n >>>? ? ? ? ? ? 670a? ? 3a6f? ? 200a? ? 2020? ? 2e20? ? 742f? ? 0a0a >>> 0000016 >>> above cmd output done? ? 2015 Sat Nov 21 04:39:47 PM PST >>> dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 >>> >>> $ make >>> cmd output started 2015 Sat Nov 21 04:39:48 PM PST >>> Makefile:3: *** missing separator.? Stop. >>> above cmd output done? ? 2015 Sat Nov 21 04:39:48 PM PST >>> dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 >>> >>> $ make --version >>> cmd output started 2015 Sat Nov 21 04:39:53 PM PST >>> GNU Make 3.81 >>> Copyright (C) 2006? Free Software Foundation, Inc. >>> This is free software; see the source for copying conditions. >>> There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A >>> PARTICULAR PURPOSE. >>> >>> This program built for i686-pc-linux-gnu >>> above cmd output done? ? 2015 Sat Nov 21 04:39:53 PM PST >>> dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 >>> >>> >>> I'll add that vim's Makefile syntax highlighting puts the >space-indented >>> line in red, suggesting an error.? Changing the spaces to a single >tab >>> makes the red go away. >>> >>> HTH >>> >>> On Sat, Nov 21, 2015 at 3:34 PM, Thomas Jakway >wrote: >>> >>>> Why would make require tabs...? >>>> Admittedly it's been a long time since I've written any makefiles >by >>>> hand >>>> but I always use spaces instead of tabs and have never had any >problems. >>>> >>>> On Nov 21, 2015 6:01 PM, David Moberg wrote: >>>> > >>>> > Have you found "soft tabs"? That option will make TextMate use >spaces >>>> instead of tab characters. Read 4.11 "Using Spaces Instead of Tabs" >in >>>> Dan >>>> Strombergs link for instrucitons. >>>> > >>>> > 2015-11-21 21:36 GMT+01:00 Jeon-Young Kang : >>>> >> >>>> >> I've tried to choose "instead of spaces". But there is no option >of >>>> mine (Textmate 2 beta). >>>> >> >>>> >> On Sat, Nov 21, 2015 at 3:14 PM, Dan Stromberg > >>>> wrote: >>>> >>> >>>> >>> >>>> >>> Perhaps enable soft tabs? >>>> >>> https://manual.macromates.com/en/working_with_text >>>> >>> >>>> >>> This is an issue in Python too (at least from PEP8's >perspective) - >>>> but note that many "make" programs require tabs instead of spaces. >>>> >>> >>>> >>> On Sat, Nov 21, 2015 at 11:13 AM, Jeon-Young Kang >>>> >>> >>>> wrote: >>>> >>>> >>>> >>>> Hello everyone. >>>> >>>> >>>> >>>> >>>> >>>> I am a newbie of Haskell, using Textmate on mac. >>>> >>>> >>>> >>>> >>>> >>>> I got the following warning. How can I fix it? >>>> >>>> >>>> >>>> >>>> >>>> Warning: >>>> >>>> >>>> >>>>? ? Tab character >>>> >>>> >>>> >>>> Ok, modules loaded: Main. >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> Sincerely, >>>> >>>> Young >>>> >>>> >>>> >>>> _______________________________________________ >>>> >>>> Beginners mailing list >>>> >>>> Beginners at haskell.org >>>> >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>>> >>>> >>> >>>> >>> >>>> >>> >>>> >>> -- >>>> >>> Dan Stromberg >>>> >>> >>>> >>> _______________________________________________ >>>> >>> Beginners mailing list >>>> >>> Beginners at haskell.org >>>> >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>> >>>> >> >>>> >> >>>> >> >>>> >> -- >>>> >> Department of Geography >>>> >> State University of New York at Buffalo >>>> >> >>>> >> jykang22 at gmail.com >>>> >> >>>> >> Jeon-Young Kang >>>> >> >>>> >> _______________________________________________ >>>> >> Beginners mailing list >>>> >> Beginners at haskell.org >>>> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >> >>>> > >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>> >>> >>> >>> -- >>> Dan Stromberg >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> >> >> -- >> Department of Geography >> State University of New York at Buffalo >> >> jykang22 at gmail.com >> >> Jeon-Young Kang >> -------------- next part -------------- >> An HTML attachment was scrubbed... >> URL: >> > >> >> ------------------------------ >> >> Message: 3 >> Date: Sat, 21 Nov 2015 20:22:04 -0500 >> From: Thomas Jakway >> To: The Haskell-Beginners Mailing List - Discussion of primarily >> ??? beginner-level topics related to Haskell >> Subject: Re: [Haskell-beginners] Warning: Tab Character >> Message-ID: <66118521-5ef8-4d50-b8dc-d65a38dd9620 at email.android.com> >> Content-Type: text/plain; charset=utf-8 >> >> Huh, cool.? I had no idea.? Thanks! >> >> On Nov 21, 2015 7:44 PM, Dan Stromberg wrote: >>> >>> >>> I believe the first version of make required tabs, but some >subsequent >>> versions have relaxed that requirement to make things easier. >>> >>> Here's an example on a Linux Mint system (the 20's are of course >spaces) >>> : >>> $ od -cx < Makefile >>> cmd output started 2015 Sat Nov 21 04:39:47 PM PST >>> 0000000? \n?? g?? o?? :? \n?????????????????? .?? /?? t? \n? \n >>> ?????????? 670a??? 3a6f??? 200a??? 2020??? 2e20??? 742f??? 0a0a >>> 0000016 >>> above cmd output done??? 2015 Sat Nov 21 04:39:47 PM PST >>> dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 >>> >>> $ make >>> cmd output started 2015 Sat Nov 21 04:39:48 PM PST >>> Makefile:3: *** missing separator.? Stop. >>> above cmd output done??? 2015 Sat Nov 21 04:39:48 PM PST >>> dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 >>> >>> $ make --version >>> cmd output started 2015 Sat Nov 21 04:39:53 PM PST >>> GNU Make 3.81 >>> Copyright (C) 2006? Free Software Foundation, Inc. >>> This is free software; see the source for copying conditions. >>> There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A >>> PARTICULAR PURPOSE. >>> >>> This program built for i686-pc-linux-gnu >>> above cmd output done??? 2015 Sat Nov 21 04:39:53 PM PST >>> dstromberg at dell-inspiron:/var/tmp/make-tabs i686-pc-linux-gnu 25234 >>> >>> >>> I'll add that vim's Makefile syntax highlighting puts the >space-indented >>> line in red, suggesting an error.? Changing the spaces to a single >tab >>> makes the red go away. >>> >>> HTH >>> >>> On Sat, Nov 21, 2015 at 3:34 PM, Thomas Jakway >wrote: >>>> >>>> Why would make require tabs...? >>>> Admittedly it's been a long time since I've written any makefiles >by hand >>>> but I always use spaces instead of tabs and have never had any >problems. >>>> >>>> On Nov 21, 2015 6:01 PM, David Moberg wrote: >>>> > >>>> > Have you found "soft tabs"? That option will make?TextMate use >spaces >>>> > instead of tab characters. Read?4.11 "Using Spaces Instead of >Tabs" in >>>> > Dan Strombergs link for instrucitons. >>>> > >>>> > 2015-11-21 21:36 GMT+01:00 Jeon-Young Kang : >>>> >> >>>> >> I've tried to choose "instead of spaces". But there is no option >of >>>> >> mine (Textmate 2 beta). >>>> >> >>>> >> On Sat, Nov 21, 2015 at 3:14 PM, Dan Stromberg > >>>> >> wrote: >>>> >>> >>>> >>> >>>> >>> Perhaps enable soft tabs? >>>> >>> https://manual.macromates.com/en/working_with_text >>>> >>> >>>> >>> This is an issue in Python too (at least from PEP8's >perspective) - >>>> >>> but note that many "make" programs require tabs instead of >spaces. >>>> >>> >>>> >>> On Sat, Nov 21, 2015 at 11:13 AM, Jeon-Young Kang >>>> >>> wrote: >>>> >>>> >>>> >>>> Hello everyone. >>>> >>>> >>>> >>>> >>>> >>>> I am a newbie of Haskell, using Textmate on mac. >>>> >>>> >>>> >>>> >>>> >>>> I got the following warning. How can I fix it? >>>> >>>> >>>> >>>> >>>> >>>> Warning: >>>> >>>> >>>> >>>> ? ? Tab character >>>> >>>> >>>> >>>> Ok, modules loaded: Main. >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> Sincerely, >>>> >>>> Young >>>> >>>> >>>> >>>> _______________________________________________ >>>> >>>> Beginners mailing list >>>> >>>> Beginners at haskell.org >>>> >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>>> >>>> >>> >>>> >>> >>>> >>> >>>> >>> -- >>>> >>> Dan Stromberg >>>> >>> >>>> >>> _______________________________________________ >>>> >>> Beginners mailing list >>>> >>> Beginners at haskell.org >>>> >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>> >>>> >> >>>> >> >>>> >> >>>> >> -- >>>> >> Department of Geography >>>> >> State University of New York at Buffalo >>>> >> >>>> >> jykang22 at gmail.com >>>> >> ? >>>> >> Jeon-Young Kang >>>> >> >>>> >> _______________________________________________ >>>> >> Beginners mailing list >>>> >> Beginners at haskell.org >>>> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >> >>>> > >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >>> >>> >>> -- >>> Dan Stromberg >> >> ------------------------------ >> >> Subject: Digest Footer >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> >> ------------------------------ >> >> End of Beginners Digest, Vol 89, Issue 38 >> ***************************************** >> >> >> >_______________________________________________ >Beginners mailing list >Beginners at haskell.org >http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners Of course, besides the numerical hierarchy problems, you also have a type incompatibility because you didn't apply take and drop to enough arguments. i.e. take (length xs `div` 2) :: [a] -> [a], whereas you seem to want take (length xs `div` 2) xs :: [a]. Also, note that you could rewrite your code to make use of the commonality of your arguments, so it becomes: > halve xs = map ($xs) . map ($ (length xs `div` 2)) $ [take, drop] (Untested, but it should work. Only possible problem I can see is that the (length xs `div` 2) section might be illegal) Sing map f . map g = map (f.g), we can rewrite this to: > halve xs = map (\f -> f (length xs `div` 2) xs) [take, drop] HTH, Gesh From jykang22 at gmail.com Tue Nov 24 18:20:03 2015 From: jykang22 at gmail.com (Jeon-Young Kang) Date: Tue, 24 Nov 2015 13:20:03 -0500 Subject: [Haskell-beginners] Comparison between fields of each record Message-ID: Dear All. I'd like to compare fields of each record. here is my record. data Person = Person {name:: String, age:: Int } deriving(Show) data Relations = Friend | Older | Younger class Comparison a where compare:: a -> a -> Relations instance Comparison Person where compare Person a b Person a b | b1 == b2 = Friend | b1 > b2 = Older | b1 < b2 = Younger How can I fit it? Sincerely, Jeon-Young Kang -------------- next part -------------- An HTML attachment was scrubbed... URL: From defigueiredo at ucdavis.edu Tue Nov 24 18:57:58 2015 From: defigueiredo at ucdavis.edu (Dimitri DeFigueiredo) Date: Tue, 24 Nov 2015 11:57:58 -0700 Subject: [Haskell-beginners] Comparison between fields of each record In-Reply-To: References: Message-ID: <5654B336.1000607@ucdavis.edu> I don't understand your question but the class Ord in Data.Ord is our tool for comparisons. You may want to look into that. You can also use the function "on" from Data.Function to compare on a specific record within a larger structure. Dimitri On 11/24/15 11:20 AM, Jeon-Young Kang wrote: > Dear All. > > I'd like to compare fields of each record. > > here is my record. > > data Person = Person {name:: String, age:: Int } deriving(Show) > data Relations = Friend | Older | Younger > > class Comparison a where > compare:: a -> a -> Relations > > instance Comparison Person where > compare Person a b Person a b > | b1 == b2 = Friend > | b1 > b2 = Older > | b1 < b2 = Younger > > How can I fit it? > > Sincerely, > > Jeon-Young Kang > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Tue Nov 24 19:01:08 2015 From: fa-ml at ariis.it (Francesco Ariis) Date: Tue, 24 Nov 2015 20:01:08 +0100 Subject: [Haskell-beginners] [Haskell-cafe] Comparison between fields of each record In-Reply-To: References: Message-ID: <20151124190108.GA4519@casa.casa> On Tue, Nov 24, 2015 at 01:20:03PM -0500, Jeon-Young Kang wrote: > Dear All. > > I'd like to compare fields of each record. > > here is my record. > > data Person = Person {name:: String, age:: Int } deriving(Show) > data Relations = Friend | Older | Younger > > class Comparison a where > compare:: a -> a -> Relations > > instance Comparison Person where > compare Person a b Person a b > | b1 == b2 = Friend > | b1 > b2 = Older > | b1 < b2 = Younger > > How can I fit it? > > Sincerely, > > > Jeon-Young Kang Hello Jeon-Young, I attach a version that compiles. Keep in mind that compare (Person x y) (Person q w) -- this is legal compare Person x y Person q w -- "space" takes precedence over everything, -- so this function has 6 arguments -- instead of the expected 2! ?> Main.compare (Person "cdsac" 1) (Person "cdscasd" 20) Younger -------------- next part -------------- A non-text attachment was scrubbed... Name: test.hs Type: text/x-haskell Size: 343 bytes Desc: not available URL: From jykang22 at gmail.com Tue Nov 24 19:14:01 2015 From: jykang22 at gmail.com (Jeon-Young Kang) Date: Tue, 24 Nov 2015 14:14:01 -0500 Subject: [Haskell-beginners] [Haskell-cafe] Comparison between fields of each record In-Reply-To: <20151124190108.GA4519@casa.casa> References: <20151124190108.GA4519@casa.casa> Message-ID: Thank you so much :) On Tue, Nov 24, 2015 at 2:01 PM, Francesco Ariis wrote: > On Tue, Nov 24, 2015 at 01:20:03PM -0500, Jeon-Young Kang wrote: > > Dear All. > > > > I'd like to compare fields of each record. > > > > here is my record. > > > > data Person = Person {name:: String, age:: Int } deriving(Show) > > data Relations = Friend | Older | Younger > > > > class Comparison a where > > compare:: a -> a -> Relations > > > > instance Comparison Person where > > compare Person a b Person a b > > | b1 == b2 = Friend > > | b1 > b2 = Older > > | b1 < b2 = Younger > > > > How can I fit it? > > > > Sincerely, > > > > > > Jeon-Young Kang > > Hello Jeon-Young, I attach a version that compiles. Keep in mind that > > compare (Person x y) (Person q w) -- this is legal > > compare Person x y Person q w -- "space" takes precedence over > everything, > -- so this function has 6 arguments > -- instead of the expected 2! > > > ?> Main.compare (Person "cdsac" 1) (Person "cdscasd" 20) > Younger > -- Department of Geography State University of New York at Buffalo jykang22 at gmail.com Jeon-Young Kang -------------- next part -------------- An HTML attachment was scrubbed... URL: From matthewjwilliams101 at gmail.com Wed Nov 25 02:42:32 2015 From: matthewjwilliams101 at gmail.com (MJ Williams) Date: Wed, 25 Nov 2015 02:42:32 +0000 Subject: [Haskell-beginners] [Haskell-cafe] Comparison between fields of each record In-Reply-To: References: <20151124190108.GA4519@casa.casa> Message-ID: Okay, can I ask you to provide a little more explanation of what you want to perform with your code? To me, at least, the question, "How can I fit it?" is a little too terse. I think before you even set up a new data, class, class instances etc., the most key step is to put in words, the simpler and cleaer the better, exactly what you what the code to do for you. Pseudo code in prose, if you like. You'll find that with clarity of thought expressed in words comes a greater command of the programming language, or at least, a clearer idea of what you want from the programming language. Matthew On 24/11/2015, Jeon-Young Kang wrote: > Thank you so much :) > > On Tue, Nov 24, 2015 at 2:01 PM, Francesco Ariis wrote: > >> On Tue, Nov 24, 2015 at 01:20:03PM -0500, Jeon-Young Kang wrote: >> > Dear All. >> > >> > I'd like to compare fields of each record. >> > >> > here is my record. >> > >> > data Person = Person {name:: String, age:: Int } deriving(Show) >> > data Relations = Friend | Older | Younger >> > >> > class Comparison a where >> > compare:: a -> a -> Relations >> > >> > instance Comparison Person where >> > compare Person a b Person a b >> > | b1 == b2 = Friend >> > | b1 > b2 = Older >> > | b1 < b2 = Younger >> > >> > How can I fit it? >> > >> > Sincerely, >> > >> > >> > Jeon-Young Kang >> >> Hello Jeon-Young, I attach a version that compiles. Keep in mind that >> >> compare (Person x y) (Person q w) -- this is legal >> >> compare Person x y Person q w -- "space" takes precedence over >> everything, >> -- so this function has 6 arguments >> -- instead of the expected 2! >> >> >> ?> Main.compare (Person "cdsac" 1) (Person "cdscasd" 20) >> Younger >> > > > > -- > Department of Geography > State University of New York at Buffalo > > jykang22 at gmail.com > > Jeon-Young Kang > From d11124067 at mydit.ie Wed Nov 25 11:39:15 2015 From: d11124067 at mydit.ie (Stephen Renehan) Date: Wed, 25 Nov 2015 11:39:15 +0000 Subject: [Haskell-beginners] Simple function comparison Message-ID: Hi, I'm looking to do a comparison between 2 simple functions to see if they are equivalent but I appear to be running into some problems if anyone can help. The two functions I want to compare are f (g a) and g (f a). I have f defined and g defined as f :: a -> a f = undefined g :: a -> a. g = undefined The compiler was complaining about the type signature lacking a binding so added undefined to get around the error. I understand that I must be missing something very basic as they look incomparable in this form. Any suggestions of what changes I should make such a comparison practical? Many thanks, Stephen -- This email originated from DIT. If you received this email in error, please delete it from your system. Please note that if you are not the named addressee, disclosing, copying, distributing or taking any action based on the contents of this email or attachments is prohibited. www.dit.ie Is ? ITB?C a th?inig an r?omhphost seo. M? fuair t? an r?omhphost seo tr? earr?id, scrios de do ch?ras ? le do thoil. Tabhair ar aird, mura t? an seola? ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon ch?ipe?il, aon d?ileadh n? ar aon ghn?omh a dh?anfar bunaithe ar an ?bhar at? sa r?omhphost n? sna hiat?in seo. www.dit.ie T? ITB?C ag aistri? go Gr?inseach Ghorm?in ? DIT is on the move to Grangegorman From dennis.raddle at gmail.com Wed Nov 25 12:37:30 2015 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Wed, 25 Nov 2015 04:37:30 -0800 Subject: [Haskell-beginners] is Haskell practical? Message-ID: I've been using Haskell for several years, but only really got into the power of the typeclasses recently. It's marvelous how pretty abstract concepts like Monoid, Monad, Functor, etc. can be used. 1. First it's remarkable how many instances they have on useful data structures. So the concepts become less abstract and more applied. 2. Second it's remarkable how the use of these concepts leads to expressive power and conciseness. Haskell is therefore a very beautiful language that seems to either be exploiting some mighty amazing coincidences or on the other hand is actually plumbing beautiful truths about the universe. But what if someone came along and said, "Well, conciseness isn't all that important. Having to type more isn't much of a drawback -- it doesn't really increase the time it takes to write a program once you consider that there is a greater time spent in requirements collection, overall design, debugging, and documentation. The real drawback of concise/expressive Haskell is the difficulty in understanding and using it fluently. Ultimately Haskell is just mathematicians having fun, but not very practical." Now, I would be sad to see someone argue this point of view, as I find Haskell to be beautiful and fun. But the learning difficulties are very real... 16 years of using imperative languages have hardly prepared my brain at all for concise/expressive Haskell. I only use it for a single hobby project and will probably never get beyond learning the list and Maybe instances of a few typeclasses. (It blows my mind to read the docs and see a dozen instances for certain typeclasses.... yikes! When would I ever be able to learn and use those?) I would just wonder what you, the reader, would say in response to an argument against the practicality of Haskell for these specific reasons: (1) conciseness isn't that important (2) it requires too much of an advanced mathematician's brain to use well. I have read it has advantages in parallel computing. What else? Or maybe you would say -- "It's not practical. So EMBRACE it. Have fun." Dennis -------------- next part -------------- An HTML attachment was scrubbed... URL: From alexander at plaimi.net Wed Nov 25 12:56:10 2015 From: alexander at plaimi.net (Alexander Berntsen) Date: Wed, 25 Nov 2015 13:56:10 +0100 Subject: [Haskell-beginners] is Haskell practical? In-Reply-To: References: Message-ID: <5655AFEA.4020700@plaimi.net> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 If the tables were turned and denotative programming were the norm and imperative programming the fringe community (not that denotative programming is entirely fringe as it were), you would no doubt have posed the opposite question. However, the tables aren't turned, and you aren't posing the opposite question, so let me give you a brief answer: Yes, Haskell is practical. To elaborate some: it is used in academia and industry. Not as much as some languages, but then again more than some other languages. Big universities like Chalmers use it, and big companies like Facebook use it. It is the primary language I myself use in industry as well. Let me repeat myself: Yes, Haskell is practical! If you have more specific questions, do not hesitate to ask. - -- Alexander alexander at plaimi.net https://secure.plaimi.net/~alexander -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCgAGBQJWVa/pAAoJENQqWdRUGk8BZ4cP/2jDPmnDKB8m5uqQmvWl1yei 0nBAv7HcWD4c3Vlo6xTn2c/KwaYZGiNwobVxnE0qiZsFZqc/GD7aThPBULDVPl2U dCmDLN4lQzXdu6k/SmHrWMZZl60U3AJ+LBkPGGJbiEa+Pi1NX1/7Jr7/755zx/K7 IIWLLa6E4ZGDBsX30raxfQzTr6A97QeBjUhFF8DMr/aVAyZR8hA+Zd3CswWtYnq4 Z5YCs7K3sFnqZafgp2el8gkJgoiSpUgB5yF/+6yn2aiX9Ez7kCwI/16CHu7DkJ/n 7WaONsPh8Q7ENirgl0rzWRTD2QpD1QWm2TAKK31ZSJVHbeOWHvP4GzGLZBg27RKR GKRTywOPCe8nsl4zP1NByxwIVVv0FTLrBFwpOHnO42mumRTn/VkUvl7w6wFf3c1A u2KCpz/wHGTnYJhukmCdmTw1DK13vLDjzqFG8JJMb5RX2IvYrFEn0RZpzjD1t+Gw mBeMqicivBC41TNgy6HlPzw8mqYcBRvMzYteuhab3WLJDnWA0DZfhvRiF6OFMFmo BWrqiD7NtojsmxIiimHb8d+2U4pYFub5M1zDZ+6RVqrn6TE4R1qz7KHsQKl7W8kL vsD4rp+04LCQCbyPGmlzJCULd/EUGN1jR+wRI/0ByUT0xcbII4kNINgJYGdhhjT0 Xu4Zq40PdC6t1yvMke4Y =Nz0V -----END PGP SIGNATURE----- From martin at vlkk.cz Wed Nov 25 13:07:43 2015 From: martin at vlkk.cz (Martin Vlk) Date: Wed, 25 Nov 2015 13:07:43 +0000 Subject: [Haskell-beginners] is Haskell practical? In-Reply-To: References: Message-ID: <5655B29F.2070708@vlkk.cz> Hey Dennis, I've been learning Hakell for a bit more than half year now. Like you, I've had all kind of doubts and I have experienced first-hand the steep learning curve. I too have asked myself whether it's worth the effort for an ordinary (read: not academically inclined and gifted) programmer to learn the language with all its high level abstractions. I have chosen to learn properly, from the ground up, using the "http://haskellbook.com/progress.html" for that, and it is taking me quite some time, because my brain is used to very different way of going about programming. I am not beyond all this, yet.. but recently I have decided to finally go and use the langage on a real project. I picked one of the issues in cabal, marked as "easy", worked out the fix for it and contributed a pull request to cabal on github. And to my surprise, I am not finding it difficult anymore to understand Haskell code, and even produce my own. I can feel that I have crossed some kind of threshold and it is not looking that haunting anymore. So I think there is no question that the language and the underlying abstractions are practical. It's more that it is a good bit unconventional in relation to the mainstream and therefore one has to switch gears before being able to use Haskell. Martin Dennis Raddle: > I've been using Haskell for several years, but only really got into the > power of the typeclasses recently. It's marvelous how pretty abstract > concepts like Monoid, Monad, Functor, etc. can be used. > > 1. First it's remarkable how many instances they have on useful data > structures. So the concepts become less abstract and more applied. > > 2. Second it's remarkable how the use of these concepts leads to expressive > power and conciseness. > > Haskell is therefore a very beautiful language that seems to either be > exploiting some mighty amazing coincidences or on the other hand is > actually plumbing beautiful truths about the universe. > > But what if someone came along and said, "Well, conciseness isn't all that > important. Having to type more isn't much of a drawback -- it doesn't > really increase the time it takes to write a program once you consider that > there is a greater time spent in requirements collection, overall design, > debugging, and documentation. The real drawback of concise/expressive > Haskell is the difficulty in understanding and using it fluently. > Ultimately Haskell is just mathematicians having fun, but not very > practical." > > Now, I would be sad to see someone argue this point of view, as I find > Haskell to be beautiful and fun. But the learning difficulties are very > real... 16 years of using imperative languages have hardly prepared my > brain at all for concise/expressive Haskell. I only use it for a single > hobby project and will probably never get beyond learning the list and > Maybe instances of a few typeclasses. (It blows my mind to read the docs > and see a dozen instances for certain typeclasses.... yikes! When would I > ever be able to learn and use those?) > > I would just wonder what you, the reader, would say in response to an > argument against the practicality of Haskell for these specific reasons: > (1) conciseness isn't that important (2) it requires too much of an > advanced mathematician's brain to use well. > > I have read it has advantages in parallel computing. What else? > > Or maybe you would say -- "It's not practical. So EMBRACE it. Have fun." > > Dennis > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From dennis.raddle at gmail.com Wed Nov 25 13:52:46 2015 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Wed, 25 Nov 2015 05:52:46 -0800 Subject: [Haskell-beginners] is Haskell practical? In-Reply-To: <5655AFEA.4020700@plaimi.net> References: <5655AFEA.4020700@plaimi.net> Message-ID: On Wed, Nov 25, 2015 at 4:56 AM, Alexander Berntsen wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA512 > > If the tables were turned and denotative programming were the norm and > imperative programming the fringe community (not that denotative > programming is entirely fringe as it were), you would no doubt have > posed the opposite question. > I don't agree. Having worked for 16 years in a government aerospace contractor doing C++ and Python programming, what I saw is that maybe half the programmers struggled with precise thinking and abstraction. They thought of programs as step-by-step recipes and implemented those recipes in exactly the same way they themselves had always thought about a problem. Also having worked as a math tutor, I see many people who struggle with abstract thinking. So my feeling is that at least half of the programmers I knew would reject Haskell outright and would feel it was pointlessly non-intuitive. Would they have thought it was intuitive if they were raised on it? I don't think so, because I think these same people were among those who struggle with all forms of abstract thought, like math students who may someday be able to appreciate a little math but are light years away from being math majors. We can pose a world in which the "tables were turned" but for that world to come into existence a lot of things would have to be changed about the current world, particularly increasing interest in abstract math from a young age. Okay, having written all that, please feel free to tear holes in my argument. I would like to be wrong and I don't have experience outside one workplace (and some math tutoring). My workplace was much better than a contractor we briefly hired. Those folks had about a 90% struggle ratio with using things like object orientation. "Just get it done, quick and dirty" was how they thought. My own workplace had some very intelligent people but between the high numbers who were just barely competent programmers, and a more "practical" orientation in the management (documentation was highly emphasized, testing was highly emphasized, but elegant code was practically unimportant), I just can't see the adoption of Haskell by them, not in this lifetime, not in this universe. Can an "okay" imperative programmer become an "okay" Haskell programmer? Does the necessary skill, work, motivation, and talent to program at an "ordinary" imperative level serve as a sufficient prerequisite for functional programming? I really don't think so, but I could be wrong. > > However, the tables aren't turned, and you aren't posing the opposite > question, so let me give you a brief answer: Yes, Haskell is practical. > > To elaborate some: it is used in academia and industry. Not as much as > some languages, but then again more than some other languages. Big > universities like Chalmers use it, and big companies like Facebook use > it. It is the primary language I myself use in industry as well. > > Let me repeat myself: Yes, Haskell is practical! > > > If you have more specific questions, do not hesitate to ask. > Yes, I do have more specific questions. For example is the conciseness part of what makes it practical in these uses? Is the conciseness somehow bound up with what makes it practical? In other words, could we imagine a simpler language with the same level of practicality but less of a learning curve? By the way, I *love* conciseness and have experienced the possibility of it becoming intuitive. It's amazing once I understand an elegant piece of Haskell, once I have wired my brain to think in harmony with it, that it becomes immediately legible. So I know it's possible to make progress. I'm not saying that conciseness must forever remain an obtuse language. But I wonder if the same mechanisms that make Haskell concise (which are some of the things that make it hard) also are bound up with its practical advantages so that they can't be separated. Dennis -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Wed Nov 25 14:20:48 2015 From: fa-ml at ariis.it (Francesco Ariis) Date: Wed, 25 Nov 2015 15:20:48 +0100 Subject: [Haskell-beginners] Simple function comparison In-Reply-To: References: Message-ID: <20151125142048.GA3305@casa.casa> On Wed, Nov 25, 2015 at 11:39:15AM +0000, Stephen Renehan wrote: > Hi, > > I'm looking to do a comparison between 2 simple functions to see if > they are equivalent but I appear to be running into some problems if > anyone can help. > > The two functions I want to compare are f (g a) and g (f a). > > I have f defined and g defined as > f :: a -> a > f = undefined > > g :: a -> a. > g = undefined > > The compiler was complaining about the type signature lacking a > binding so added undefined to get around the error. I understand that > I must be missing something very basic as they look incomparable in > this form. Any suggestions of what changes I should make such a > comparison practical? Hello Stephen, I don't think there is a way to /prove/ f (g a) == g (f a) if their domain is not finite inside Haskell (you could do it with pen and paper). If you have two functions and a finite domain you can do, say: -- function function domain compfun :: (Eq a) => (a -> a) -> (a -> a) -> [a] -> Bool compfun f g d = and $ map (\x -> (f . g) x == (g . f) x) d ?> compfun (+1) (+17) [1..10] True ?> compfun (*5) (+17) [1..10] False Of course this is a toy example, use a proper library (quickcheck, etc.) if you are writing a real program. From d11124067 at mydit.ie Wed Nov 25 14:32:07 2015 From: d11124067 at mydit.ie (Stephen Renehan) Date: Wed, 25 Nov 2015 14:32:07 +0000 Subject: [Haskell-beginners] Simple function comparison In-Reply-To: <20151125142048.GA3305@casa.casa> References: <20151125142048.GA3305@casa.casa> Message-ID: Many thanks Franceso, I had thought as much as I was dealing with them only abstractly. Appreciate the quick reply and thanks for the help. On 25 November 2015 at 14:20, Francesco Ariis wrote: > On Wed, Nov 25, 2015 at 11:39:15AM +0000, Stephen Renehan wrote: >> Hi, >> >> I'm looking to do a comparison between 2 simple functions to see if >> they are equivalent but I appear to be running into some problems if >> anyone can help. >> >> The two functions I want to compare are f (g a) and g (f a). >> >> I have f defined and g defined as >> f :: a -> a >> f = undefined >> >> g :: a -> a. >> g = undefined >> >> The compiler was complaining about the type signature lacking a >> binding so added undefined to get around the error. I understand that >> I must be missing something very basic as they look incomparable in >> this form. Any suggestions of what changes I should make such a >> comparison practical? > > Hello Stephen, > I don't think there is a way to /prove/ f (g a) == g (f a) if their > domain is not finite inside Haskell (you could do it with pen and > paper). > > If you have two functions and a finite domain you can do, say: > > -- function function domain > compfun :: (Eq a) => (a -> a) -> (a -> a) -> [a] -> Bool > compfun f g d = and $ map (\x -> (f . g) x == (g . f) x) d > > ?> compfun (+1) (+17) [1..10] > True > ?> compfun (*5) (+17) [1..10] > False > > Of course this is a toy example, use a proper library (quickcheck, etc.) > if you are writing a real program. > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -- This email originated from DIT. If you received this email in error, please delete it from your system. Please note that if you are not the named addressee, disclosing, copying, distributing or taking any action based on the contents of this email or attachments is prohibited. www.dit.ie Is ? ITB?C a th?inig an r?omhphost seo. M? fuair t? an r?omhphost seo tr? earr?id, scrios de do ch?ras ? le do thoil. Tabhair ar aird, mura t? an seola? ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon ch?ipe?il, aon d?ileadh n? ar aon ghn?omh a dh?anfar bunaithe ar an ?bhar at? sa r?omhphost n? sna hiat?in seo. www.dit.ie T? ITB?C ag aistri? go Gr?inseach Ghorm?in ? DIT is on the move to Grangegorman From matthewjwilliams101 at gmail.com Wed Nov 25 15:48:08 2015 From: matthewjwilliams101 at gmail.com (MJ Williams) Date: Wed, 25 Nov 2015 15:48:08 +0000 Subject: [Haskell-beginners] Simple function comparison In-Reply-To: <20151125142048.GA3305@casa.casa> References: <20151125142048.GA3305@casa.casa> Message-ID: <5655d836.07b71c0a.5d6b.6119@mx.google.com> [snip] >I don't think there is a way to /prove/ f (g a) == g (f a) if their >domain is not finite inside Haskell (you could do it with pen and paper). [snip] Just out of interest, could you demonstrate the proof without a finite domain? Sincerely, Matthew From fa-ml at ariis.it Wed Nov 25 16:22:50 2015 From: fa-ml at ariis.it (Francesco Ariis) Date: Wed, 25 Nov 2015 17:22:50 +0100 Subject: [Haskell-beginners] Simple function comparison In-Reply-To: <5655d836.07b71c0a.5d6b.6119@mx.google.com> References: <20151125142048.GA3305@casa.casa> <5655d836.07b71c0a.5d6b.6119@mx.google.com> Message-ID: <20151125162027.GA5344@casa.casa> On Wed, Nov 25, 2015 at 03:48:08PM +0000, MJ Williams wrote: > [snip] > > >I don't think there is a way to /prove/ f (g a) == g (f a) if their domain > >is not finite inside Haskell (you could do it with pen and paper). > [snip] > Just out of interest, could you demonstrate the proof without a > finite domain? > > Sincerely, Matthew Say we have: f(x) = x + 1 g(x) = x + 7 Then we can substitute: f(g(x)) f(x+7) (x+7) + 1 x+8 and g(f(x)) g(x+1) (x+1) + 7 x+8 which shows f(g(x)) = g(f(x)) For anything more, my lawyer suggested I say: I have discovered a truly marvellous proof for it, but the margin of this email is to narrow to contain it. :P From d11124067 at mydit.ie Wed Nov 25 16:35:04 2015 From: d11124067 at mydit.ie (Stephen Renehan) Date: Wed, 25 Nov 2015 16:35:04 +0000 Subject: [Haskell-beginners] Simple function comparison In-Reply-To: <5655d836.07b71c0a.5d6b.6119@mx.google.com> References: <20151125142048.GA3305@casa.casa> <5655d836.07b71c0a.5d6b.6119@mx.google.com> Message-ID: Hi Matthew, Was just about to reply that I only have the process written in long hand from the video that I enclose but I see Francesco beat me to it with a more concise explanation. Thanks again Francesco :) https://www.youtube.com/watch?v=ZhuHCtR3xq8 On 25 November 2015 at 15:48, MJ Williams wrote: > [snip] > >> I don't think there is a way to /prove/ f (g a) == g (f a) if their domain >> is not finite inside Haskell (you could do it with pen and paper). > > [snip] > Just out of interest, could you demonstrate the proof without a > finite domain? > > Sincerely, Matthew > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -- This email originated from DIT. If you received this email in error, please delete it from your system. Please note that if you are not the named addressee, disclosing, copying, distributing or taking any action based on the contents of this email or attachments is prohibited. www.dit.ie Is ? ITB?C a th?inig an r?omhphost seo. M? fuair t? an r?omhphost seo tr? earr?id, scrios de do ch?ras ? le do thoil. Tabhair ar aird, mura t? an seola? ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon ch?ipe?il, aon d?ileadh n? ar aon ghn?omh a dh?anfar bunaithe ar an ?bhar at? sa r?omhphost n? sna hiat?in seo. www.dit.ie T? ITB?C ag aistri? go Gr?inseach Ghorm?in ? DIT is on the move to Grangegorman From objitsu at gmail.com Wed Nov 25 16:54:53 2015 From: objitsu at gmail.com (emacstheviking) Date: Wed, 25 Nov 2015 16:54:53 +0000 Subject: [Haskell-beginners] Simple function comparison In-Reply-To: References: <20151125142048.GA3305@casa.casa> <5655d836.07b71c0a.5d6b.6119@mx.google.com> Message-ID: Awesome video, I watched it about ten times in a row and so many pennies dropped. On 25 November 2015 at 16:35, Stephen Renehan wrote: > Hi Matthew, > > Was just about to reply that I only have the process written in long > hand from the video that I enclose but I see Francesco beat me to it > with a more concise explanation. Thanks again Francesco :) > > https://www.youtube.com/watch?v=ZhuHCtR3xq8 > > > On 25 November 2015 at 15:48, MJ Williams > wrote: > > [snip] > > > >> I don't think there is a way to /prove/ f (g a) == g (f a) if their > domain > >> is not finite inside Haskell (you could do it with pen and paper). > > > > [snip] > > Just out of interest, could you demonstrate the proof without a > > finite domain? > > > > Sincerely, Matthew > > > > > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- > > > This email originated from DIT. If you received this email in error, please > delete it from your system. Please note that if you are not the named > addressee, disclosing, copying, distributing or taking any action based on > the contents of this email or attachments is prohibited. www.dit.ie > > Is ? ITB?C a th?inig an r?omhphost seo. M? fuair t? an r?omhphost seo tr? > earr?id, scrios de do ch?ras ? le do thoil. Tabhair ar aird, mura t? an > seola? ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon ch?ipe?il, aon > d?ileadh n? ar aon ghn?omh a dh?anfar bunaithe ar an ?bhar at? sa > r?omhphost n? sna hiat?in seo. www.dit.ie > > T? ITB?C ag aistri? go Gr?inseach Ghorm?in ? DIT is on the move to > Grangegorman > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin at vlkk.cz Wed Nov 25 17:50:07 2015 From: martin at vlkk.cz (Martin Vlk) Date: Wed, 25 Nov 2015 17:50:07 +0000 Subject: [Haskell-beginners] is Haskell practical? In-Reply-To: References: <5655AFEA.4020700@plaimi.net> Message-ID: <5655F4CF.9000807@vlkk.cz> Dennis Raddle: > On Wed, Nov 25, 2015 at 4:56 AM, Alexander Berntsen > wrote: > I don't agree. Having worked for 16 years in a government aerospace > contractor doing C++ and Python programming, what I saw is that maybe half > the programmers struggled with precise thinking and abstraction. They > thought of programs as step-by-step recipes and implemented those recipes > in exactly the same way they themselves had always thought about a problem. > > Also having worked as a math tutor, I see many people who struggle with > abstract thinking. > Can an "okay" imperative programmer become an "okay" Haskell programmer? > Does the necessary skill, work, motivation, and talent to program at an > "ordinary" imperative level serve as a sufficient prerequisite for > functional programming? I really don't think so, but I could be wrong. What'd be the definition of an okay programmer? If we agree that's the one that "learns how to solve a few standard problems and then applies the same thing over and over without much creativity", then I'll argue this will work with Haskell just like with any imperative language. If you train them on Haskell that is. :-) > But I wonder if the same mechanisms that make Haskell concise (which are > some of the things that make it hard) also are bound up with its practical > advantages so that they can't be separated. What you mean by practical? Does it mean that you can find enough people able to use it in your real-world project, without putting too high requirements on training them? If so, then we could say that given the current state of affairs, where the mass of okay programmers are trained on a different paradigm, Haskell is not all that practical. But if practical means that the language is well suited for solving real-world problems, in beautiful ways, once you get it, then it is uberpractical! :-) M. From kc1956 at gmail.com Wed Nov 25 18:13:35 2015 From: kc1956 at gmail.com (KC) Date: Wed, 25 Nov 2015 10:13:35 -0800 Subject: [Haskell-beginners] is Haskell practical? In-Reply-To: <5655F4CF.9000807@vlkk.cz> References: <5655AFEA.4020700@plaimi.net> <5655F4CF.9000807@vlkk.cz> Message-ID: Yes Haskell is practical except for finding Haskell replacement programmers. -- -- Sent from an expensive device which will be obsolete in a few months! :D Casey On Nov 25, 2015 9:50 AM, "Martin Vlk" wrote: > > > Dennis Raddle: > > On Wed, Nov 25, 2015 at 4:56 AM, Alexander Berntsen < > alexander at plaimi.net> > > wrote: > > > > > I don't agree. Having worked for 16 years in a government aerospace > > contractor doing C++ and Python programming, what I saw is that maybe > half > > the programmers struggled with precise thinking and abstraction. They > > thought of programs as step-by-step recipes and implemented those recipes > > in exactly the same way they themselves had always thought about a > problem. > > > > Also having worked as a math tutor, I see many people who struggle with > > abstract thinking. > > > > > Can an "okay" imperative programmer become an "okay" Haskell programmer? > > Does the necessary skill, work, motivation, and talent to program at an > > "ordinary" imperative level serve as a sufficient prerequisite for > > functional programming? I really don't think so, but I could be wrong. > > What'd be the definition of an okay programmer? If we agree that's the > one that "learns how to solve a few standard problems and then applies > the same thing over and over without much creativity", then I'll argue > this will work with Haskell just like with any imperative language. If > you train them on Haskell that is. :-) > > > > > But I wonder if the same mechanisms that make Haskell concise (which are > > some of the things that make it hard) also are bound up with its > practical > > advantages so that they can't be separated. > > What you mean by practical? Does it mean that you can find enough people > able to use it in your real-world project, without putting too high > requirements on training them? > > If so, then we could say that given the current state of affairs, where > the mass of okay programmers are trained on a different paradigm, > Haskell is not all that practical. > > But if practical means that the language is well suited for solving > real-world problems, in beautiful ways, once you get it, then it is > uberpractical! :-) > > M. > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hjgtuyl at chello.nl Wed Nov 25 23:49:45 2015 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Thu, 26 Nov 2015 00:49:45 +0100 Subject: [Haskell-beginners] Simple function comparison In-Reply-To: References: Message-ID: On Wed, 25 Nov 2015 12:39:15 +0100, Stephen Renehan wrote: > Hi, > > I'm looking to do a comparison between 2 simple functions to see if > they are equivalent but I appear to be running into some problems if > anyone can help. > > The two functions I want to compare are f (g a) and g (f a). > > I have f defined and g defined as > f :: a -> a > f = undefined > > g :: a -> a. > g = undefined As you can not say anything about the type of input or output (except that they are equal), the only normally terminating function possible is 'id'. So, if you don't want to use 'undefined' or 'error', f and g are equal. 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 matthewjwilliams101 at gmail.com Thu Nov 26 08:39:31 2015 From: matthewjwilliams101 at gmail.com (MJ Williams) Date: Thu, 26 Nov 2015 08:39:31 +0000 Subject: [Haskell-beginners] Simple function comparison In-Reply-To: References: Message-ID: All right, how about this for a proof: Let f x = x + 1 let g x = x + 2 if f ( g a ) then f ( a + 2 ) .............. (g) then ( a + 2 ) + 1 ............ (f) ... then a + 3 .................... (+) therefore f ( g a ) <-> a + 3 if g ( f a ) then g ( a + 1 ) .............. (f) then ( a + 1 ) + 2 ............ (g) ... then a + 3 .................... (+) therefore g ( f a ) <-> a + 3 therefore f ( g a ) = g ( f a ) (transitivity) Feel free to take it apart and smash it to bits. Seriously, any feedback welcome. Cheers, Matthew On 25/11/2015, Henk-Jan van Tuyl wrote: > On Wed, 25 Nov 2015 12:39:15 +0100, Stephen Renehan > wrote: > >> Hi, >> >> I'm looking to do a comparison between 2 simple functions to see if >> they are equivalent but I appear to be running into some problems if >> anyone can help. >> >> The two functions I want to compare are f (g a) and g (f a). >> >> I have f defined and g defined as >> f :: a -> a >> f = undefined >> >> g :: a -> a. >> g = undefined > > As you can not say anything about the type of input or output (except that > > they are equal), the only normally terminating function possible is 'id'. > So, if you don't want to use 'undefined' or 'error', f and g are equal. > > 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 > -- > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From objitsu at gmail.com Thu Nov 26 09:06:14 2015 From: objitsu at gmail.com (emacstheviking) Date: Thu, 26 Nov 2015 09:06:14 +0000 Subject: [Haskell-beginners] is Haskell practical? In-Reply-To: References: <5655AFEA.4020700@plaimi.net> <5655F4CF.9000807@vlkk.cz> Message-ID: I read all the above. I have to agree with KC... I have been a software developer for 30+ years now and I would dearly love to be able to use Haskell in my day to day tasks when being paid. As an IT contractor in the UK however that just isn't going to happen. By and large the management / project planning mentality is "lowest common denominator" when it comes to large IT projects. It's not hard to understand the reasons and from a commercial and business perspective it makes sense, of course it does. I've been working on the UK MOT programme (now complete) for the last 18 months and it was all PHP, Zend Framework 2 and Doctrine because that skill pool is huge compared to Haskell and when it comes to having a ready supply of code capable meat-sacks to deliver stories on time, LCD is where it will always be. TIOBE says that Java has been top dog for ever. I rest my case. Us in the haskell world realise that people that can use Haskell effectively would be much more productive, and probably produce a lot more functional(!) code in a shorter space of time, have a high sprint velocity, deliver more stories etc. Quickcheck is inspired! The thought of being on an Agile team using haskell, wow, that's too much to hope for... All the best, Sean Charles On 25 November 2015 at 18:13, KC wrote: > Yes Haskell is practical except for finding Haskell replacement > programmers. > > -- > -- > > Sent from an expensive device which will be obsolete in a few months! :D > > Casey > > On Nov 25, 2015 9:50 AM, "Martin Vlk" wrote: > >> >> >> Dennis Raddle: >> > On Wed, Nov 25, 2015 at 4:56 AM, Alexander Berntsen < >> alexander at plaimi.net> >> > wrote: >> >> >> >> > I don't agree. Having worked for 16 years in a government aerospace >> > contractor doing C++ and Python programming, what I saw is that maybe >> half >> > the programmers struggled with precise thinking and abstraction. They >> > thought of programs as step-by-step recipes and implemented those >> recipes >> > in exactly the same way they themselves had always thought about a >> problem. >> > >> > Also having worked as a math tutor, I see many people who struggle with >> > abstract thinking. >> >> >> >> > Can an "okay" imperative programmer become an "okay" Haskell programmer? >> > Does the necessary skill, work, motivation, and talent to program at an >> > "ordinary" imperative level serve as a sufficient prerequisite for >> > functional programming? I really don't think so, but I could be wrong. >> >> What'd be the definition of an okay programmer? If we agree that's the >> one that "learns how to solve a few standard problems and then applies >> the same thing over and over without much creativity", then I'll argue >> this will work with Haskell just like with any imperative language. If >> you train them on Haskell that is. :-) >> >> >> >> > But I wonder if the same mechanisms that make Haskell concise (which are >> > some of the things that make it hard) also are bound up with its >> practical >> > advantages so that they can't be separated. >> >> What you mean by practical? Does it mean that you can find enough people >> able to use it in your real-world project, without putting too high >> requirements on training them? >> >> If so, then we could say that given the current state of affairs, where >> the mass of okay programmers are trained on a different paradigm, >> Haskell is not all that practical. >> >> But if practical means that the language is well suited for solving >> real-world problems, in beautiful ways, once you get it, then it is >> uberpractical! :-) >> >> M. >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From matthewjwilliams101 at gmail.com Thu Nov 26 09:33:51 2015 From: matthewjwilliams101 at gmail.com (MJ Williams) Date: Thu, 26 Nov 2015 09:33:51 +0000 Subject: [Haskell-beginners] is Haskell practical? In-Reply-To: References: <5655AFEA.4020700@plaimi.net> <5655F4CF.9000807@vlkk.cz> Message-ID: "lowest common denominator" Right on, Sean. That pretty much sums up the state of affairs. I would however say that the sort of culture, mindset, if you will, agile development encourages might not be entirely compatible with the thinking process and general view of the universe that FP requires. I could be mistaken on this entirely, but agile strikes me as something that would b much more at home in an essentially business-oriented environment used by people of that background e.g. people who thrive on using UML. Matthew On 26/11/2015, emacstheviking wrote: > I read all the above. I have to agree with KC... I have been a software > developer for 30+ years now and I would dearly love to be able to use > Haskell in my day to day tasks when being paid. As an IT contractor in the > UK however that just isn't going to happen. By and large the management / > project planning mentality is "lowest common denominator" when it comes to > large IT projects. It's not hard to understand the reasons and from a > commercial and business perspective it makes sense, of course it does. > > I've been working on the UK MOT programme (now complete) for the last 18 > months and it was all PHP, Zend Framework 2 and Doctrine because that skill > pool is huge compared to Haskell and when it comes to having a ready supply > of code capable meat-sacks to deliver stories on time, LCD is where it will > always be. TIOBE says that Java has been top dog for ever. I rest my case. > > Us in the haskell world realise that people that can use Haskell > effectively would be much more productive, and probably produce a lot more > functional(!) code in a shorter space of time, have a high sprint velocity, > deliver more stories etc. Quickcheck is inspired! > > The thought of being on an Agile team using haskell, wow, that's too much > to hope for... > > All the best, > Sean Charles > > On 25 November 2015 at 18:13, KC wrote: > >> Yes Haskell is practical except for finding Haskell replacement >> programmers. >> >> -- >> -- >> >> Sent from an expensive device which will be obsolete in a few months! :D >> >> Casey >> >> On Nov 25, 2015 9:50 AM, "Martin Vlk" wrote: >> >>> >>> >>> Dennis Raddle: >>> > On Wed, Nov 25, 2015 at 4:56 AM, Alexander Berntsen < >>> alexander at plaimi.net> >>> > wrote: >>> >>> >>> >>> > I don't agree. Having worked for 16 years in a government aerospace >>> > contractor doing C++ and Python programming, what I saw is that maybe >>> half >>> > the programmers struggled with precise thinking and abstraction. They >>> > thought of programs as step-by-step recipes and implemented those >>> recipes >>> > in exactly the same way they themselves had always thought about a >>> problem. >>> > >>> > Also having worked as a math tutor, I see many people who struggle >>> > with >>> > abstract thinking. >>> >>> >>> >>> > Can an "okay" imperative programmer become an "okay" Haskell >>> > programmer? >>> > Does the necessary skill, work, motivation, and talent to program at >>> > an >>> > "ordinary" imperative level serve as a sufficient prerequisite for >>> > functional programming? I really don't think so, but I could be wrong. >>> >>> What'd be the definition of an okay programmer? If we agree that's the >>> one that "learns how to solve a few standard problems and then applies >>> the same thing over and over without much creativity", then I'll argue >>> this will work with Haskell just like with any imperative language. If >>> you train them on Haskell that is. :-) >>> >>> >>> >>> > But I wonder if the same mechanisms that make Haskell concise (which >>> > are >>> > some of the things that make it hard) also are bound up with its >>> practical >>> > advantages so that they can't be separated. >>> >>> What you mean by practical? Does it mean that you can find enough people >>> able to use it in your real-world project, without putting too high >>> requirements on training them? >>> >>> If so, then we could say that given the current state of affairs, where >>> the mass of okay programmers are trained on a different paradigm, >>> Haskell is not all that practical. >>> >>> But if practical means that the language is well suited for solving >>> real-world problems, in beautiful ways, once you get it, then it is >>> uberpractical! :-) >>> >>> M. >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > From matthewjwilliams101 at gmail.com Thu Nov 26 11:20:05 2015 From: matthewjwilliams101 at gmail.com (MJ Williams) Date: Thu, 26 Nov 2015 11:20:05 +0000 Subject: [Haskell-beginners] Simple function comparison In-Reply-To: References: Message-ID: All right, a revised version: Let f x = x + 1 let g x = x + 2 f ( g a ) = f ( a + 2 ) ................... (g) = ( a + 2 ) + 1 ................. (f) ... = a + 3 ......................... (+) therefore f ( g a ) <-> a + 3 ... (transitivity) g ( f a ) = g ( a + 1 ) ................... (f) = ( a + 1 ) + 2 ................. (g) ... = a + 3 ......................... (+) therefore g ( f a ) <-> a + 3 ... (transitivity) therefore f ( g a ) = g ( f a ) . (transitivity) On 26/11/2015, MJ Williams wrote: > All right, how about this for a proof: > > Let f x = x + 1 > let g x = x + 2 > > if f ( g a ) > then f ( a + 2 ) .............. (g) > then ( a + 2 ) + 1 ............ (f) > ... > then a + 3 .................... (+) > therefore f ( g a ) <-> a + 3 > > if g ( f a ) > then g ( a + 1 ) .............. (f) > then ( a + 1 ) + 2 ............ (g) > ... > then a + 3 .................... (+) > therefore g ( f a ) <-> a + 3 > > therefore f ( g a ) = g ( f a ) (transitivity) > > Feel free to take it apart and smash it to bits. Seriously, any > feedback welcome. > > Cheers, Matthew > > > On 25/11/2015, Henk-Jan van Tuyl wrote: >> On Wed, 25 Nov 2015 12:39:15 +0100, Stephen Renehan >> wrote: >> >>> Hi, >>> >>> I'm looking to do a comparison between 2 simple functions to see if >>> they are equivalent but I appear to be running into some problems if >>> anyone can help. >>> >>> The two functions I want to compare are f (g a) and g (f a). >>> >>> I have f defined and g defined as >>> f :: a -> a >>> f = undefined >>> >>> g :: a -> a. >>> g = undefined >> >> As you can not say anything about the type of input or output (except >> that >> >> they are equal), the only normally terminating function possible is 'id'. >> So, if you don't want to use 'undefined' or 'error', f and g are equal. >> >> 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 >> -- >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > From ky3 at atamo.com Thu Nov 26 11:53:09 2015 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Thu, 26 Nov 2015 18:53:09 +0700 Subject: [Haskell-beginners] Simple function comparison In-Reply-To: References: Message-ID: On Thu, Nov 26, 2015 at 6:20 PM, MJ Williams wrote: therefore f ( g a ) = g ( f a ) . (transitivity) If you're interested in getting a firm grasp of airtight proofs -- with a view toward Haskell (and Agda and Idris) mastery -- you might want to pick and choose your way through the web-based proof exercises here: https://www.coursera.org/course/intrologic This is a course firmly in the American analytic philosophy tradition, so Logic here is Symbolic Logic. Bonus: the course keeps AI and Machine Learning applications in the backdrop. It's unfortunate that it's some kind of well-kept secret. Those who don't need it -- because they've obtained the knowledge elsewhere -- won't know about it. And those who do want that knowledge also won't know about it. Did I mention the exercises are web-based? Yes, you get instantaneous feedback on whether you've got a correct proof or not. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From matthewjwilliams101 at gmail.com Thu Nov 26 12:22:19 2015 From: matthewjwilliams101 at gmail.com (MJ Williams) Date: Thu, 26 Nov 2015 12:22:19 +0000 Subject: [Haskell-beginners] Simple function comparison In-Reply-To: References: Message-ID: <5656f977.aa0bc30a.290ed.2470@mx.google.com> That's great, thanks. Matt At 11:53 26/11/2015, you wrote: >On Thu, Nov 26, 2015 at 6:20 PM, MJ Williams ><matthewjwilliams101 at gmail.com> wrote: > > >therefore f ( g a ) = g ( f a ) . (transitivity) > > >If you're interested in getting a firm grasp of airtight proofs -- >with a view toward Haskell (and Agda and Idris) mastery -- you might >want to pick and choose your way through the web-based proof exercises here: > >https://www.coursera.org/course/intrologic > >This is a course firmly in the American analytic philosophy >tradition, so Logic here is Symbolic Logic. Bonus: the course keeps >AI and Machine Learning applications in the backdrop. > >It's unfortunate that it's some kind of well-kept secret. > >Those who don't need it -- because they've obtained the knowledge >elsewhere -- won't know about it. And those who do want that >knowledge also won't know about it. > >Did I mention the exercises are web-based? Yes, you get >instantaneous feedback on whether you've got a correct proof or not. > >-- Kim-Ee >_______________________________________________ >Beginners mailing list >Beginners at haskell.org >http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From frederic-emmanuel.picca at synchrotron-soleil.fr Thu Nov 26 12:50:49 2015 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Thu, 26 Nov 2015 12:50:49 +0000 Subject: [Haskell-beginners] ffi array and peekArray In-Reply-To: References: , Message-ID: Thanks a lot it works now :) ________________________________________ De : Beginners [beginners-bounces at haskell.org] de la part de Sylvain Henry [hsyl20 at gmail.com] Envoy? : dimanche 8 novembre 2015 21:45 ? : The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell Objet : Re: [Haskell-beginners] ffi array and peekArray You can alias HklFactory: type HklFactory = Ptr () Or if you want to avoid mixing HklFactory and other pointers, you can use: newtype HklFactory = HklFactory (Ptr ()) deriving (Storable) The latter requires the GeneralizedNewtypeDeriving extension, see: https://wiki.haskell.org/Foreign_Function_Interface#Renaming_and_Storable_instances Sylvain 2015-11-08 21:30 GMT+01:00 PICCA Frederic-Emmanuel >: Ok, so now I get this error ghkl.hs:20:18: No instance for (Foreign.Storable.Storable HklFactory) arising from a use of ?peekArray? In a stmt of a 'do' block: peekArray n factories In the expression: do { factories <- c_hkl_factory_get_all ptr; n <- peek ptr; peekArray n factories } In the second argument of ?($)?, namely ?\ ptr -> do { factories <- c_hkl_factory_get_all ptr; n <- peek ptr; .... }? What should I do to create a Storable for HklFactory which is a simple pointer. Thanks Frederic _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From objitsu at gmail.com Thu Nov 26 14:13:02 2015 From: objitsu at gmail.com (emacstheviking) Date: Thu, 26 Nov 2015 14:13:02 +0000 Subject: [Haskell-beginners] is Haskell practical? In-Reply-To: References: <5655AFEA.4020700@plaimi.net> <5655F4CF.9000807@vlkk.cz> Message-ID: Matthew, Agile is "just a process"... presumably it can deliver *anything* not just software projects. There's a lot of software people I know who look very surprised when you tell them where and why "kanban" was developed! Either way, Haskell isn't mainstream and sadly is unlikely to become so, at leat not this century unless the educational system in the UK improves markedly! Let's just all use it when and where we can and keep spreading the word! Sean. On 26 November 2015 at 09:33, MJ Williams wrote: > "lowest common denominator" > Right on, Sean. That pretty much sums up the state of affairs. > I would however say that the sort of culture, mindset, if you will, > agile development encourages might not be entirely compatible with the > thinking process and general view of the universe that FP requires. I > could be mistaken on this entirely, but agile strikes me as something > that would b much more at home in an essentially business-oriented > environment used by people of that background e.g. people who thrive > on using UML. > Matthew > > > On 26/11/2015, emacstheviking wrote: > > I read all the above. I have to agree with KC... I have been a software > > developer for 30+ years now and I would dearly love to be able to use > > Haskell in my day to day tasks when being paid. As an IT contractor in > the > > UK however that just isn't going to happen. By and large the management / > > project planning mentality is "lowest common denominator" when it comes > to > > large IT projects. It's not hard to understand the reasons and from a > > commercial and business perspective it makes sense, of course it does. > > > > I've been working on the UK MOT programme (now complete) for the last 18 > > months and it was all PHP, Zend Framework 2 and Doctrine because that > skill > > pool is huge compared to Haskell and when it comes to having a ready > supply > > of code capable meat-sacks to deliver stories on time, LCD is where it > will > > always be. TIOBE says that Java has been top dog for ever. I rest my > case. > > > > Us in the haskell world realise that people that can use Haskell > > effectively would be much more productive, and probably produce a lot > more > > functional(!) code in a shorter space of time, have a high sprint > velocity, > > deliver more stories etc. Quickcheck is inspired! > > > > The thought of being on an Agile team using haskell, wow, that's too much > > to hope for... > > > > All the best, > > Sean Charles > > > > On 25 November 2015 at 18:13, KC wrote: > > > >> Yes Haskell is practical except for finding Haskell replacement > >> programmers. > >> > >> -- > >> -- > >> > >> Sent from an expensive device which will be obsolete in a few months! :D > >> > >> Casey > >> > >> On Nov 25, 2015 9:50 AM, "Martin Vlk" wrote: > >> > >>> > >>> > >>> Dennis Raddle: > >>> > On Wed, Nov 25, 2015 at 4:56 AM, Alexander Berntsen < > >>> alexander at plaimi.net> > >>> > wrote: > >>> > >>> > >>> > >>> > I don't agree. Having worked for 16 years in a government aerospace > >>> > contractor doing C++ and Python programming, what I saw is that maybe > >>> half > >>> > the programmers struggled with precise thinking and abstraction. They > >>> > thought of programs as step-by-step recipes and implemented those > >>> recipes > >>> > in exactly the same way they themselves had always thought about a > >>> problem. > >>> > > >>> > Also having worked as a math tutor, I see many people who struggle > >>> > with > >>> > abstract thinking. > >>> > >>> > >>> > >>> > Can an "okay" imperative programmer become an "okay" Haskell > >>> > programmer? > >>> > Does the necessary skill, work, motivation, and talent to program at > >>> > an > >>> > "ordinary" imperative level serve as a sufficient prerequisite for > >>> > functional programming? I really don't think so, but I could be > wrong. > >>> > >>> What'd be the definition of an okay programmer? If we agree that's the > >>> one that "learns how to solve a few standard problems and then applies > >>> the same thing over and over without much creativity", then I'll argue > >>> this will work with Haskell just like with any imperative language. If > >>> you train them on Haskell that is. :-) > >>> > >>> > >>> > >>> > But I wonder if the same mechanisms that make Haskell concise (which > >>> > are > >>> > some of the things that make it hard) also are bound up with its > >>> practical > >>> > advantages so that they can't be separated. > >>> > >>> What you mean by practical? Does it mean that you can find enough > people > >>> able to use it in your real-world project, without putting too high > >>> requirements on training them? > >>> > >>> If so, then we could say that given the current state of affairs, where > >>> the mass of okay programmers are trained on a different paradigm, > >>> Haskell is not all that practical. > >>> > >>> But if practical means that the language is well suited for solving > >>> real-world problems, in beautiful ways, once you get it, then it is > >>> uberpractical! :-) > >>> > >>> M. > >>> _______________________________________________ > >>> Beginners mailing list > >>> Beginners at haskell.org > >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > >>> > >> > >> _______________________________________________ > >> Beginners mailing list > >> Beginners at haskell.org > >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > >> > >> > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ondra at nekola.cz Fri Nov 27 09:13:54 2015 From: ondra at nekola.cz (Ondrej Nekola) Date: Fri, 27 Nov 2015 10:13:54 +0100 Subject: [Haskell-beginners] REPL with visualisation Message-ID: <56581ED2.8080101@nekola.cz> Hi Just curious: is there some recommended "first choice" combination of REPL and libs for (Apple) Swift styled "playgrounds"? (I have just seen a fractalish coffee spill and remembered that I have not implemented Mandelbrot set since high school and Pascal days and maybe it's time to be a bit childish again). Thanks Ondra 'satai' Nekola ondra at nekola.cz From dennis.raddle at gmail.com Fri Nov 27 13:17:10 2015 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Fri, 27 Nov 2015 05:17:10 -0800 Subject: [Haskell-beginners] is Haskell practical? In-Reply-To: <5655F4CF.9000807@vlkk.cz> References: <5655AFEA.4020700@plaimi.net> <5655F4CF.9000807@vlkk.cz> Message-ID: On Wed, Nov 25, 2015 at 9:50 AM, Martin Vlk wrote: > > > > > What'd be the definition of an okay programmer? If we agree that's the > one that "learns how to solve a few standard problems and then applies > the same thing over and over without much creativity", then I'll argue > this will work with Haskell just like with any imperative language. If > you train them on Haskell that is. :-) > > > > Martin, One issue I can foresee is having both good Haskell programmers and non-creative Haskell programmers on the same team. The good ones can easily write code that is incomprehensible to the non-creative ones. It actually happened in my team twice that C++ code was thrown out and assigned to someone else for a complete rewrite, because the senior software engineer deemed that the original code was incomprehensible. In both cases it was code that used a few tricks that I think were good, and in both cases the replacement code was buggier. > > But I wonder if the same mechanisms that make Haskell concise (which are > > some of the things that make it hard) also are bound up with its > practical > > advantages so that they can't be separated. > > What you mean by practical? Does it mean that you can find enough people > able to use it in your real-world project, without putting too high > requirements on training them? > > If so, then we could say that given the current state of affairs, where > the mass of okay programmers are trained on a different paradigm, > Haskell is not all that practical. > > But if practical means that the language is well suited for solving > real-world problems, in beautiful ways, once you get it, then it is > uberpractical! :-) > > Very well put. I didn't really think about what meant by "practical," and it depends on context. I am gaining some Haskell momentum, and I see how the potential for conciseness seems to encourage the kind of thinking about a problem that leads to simplifications and optimizations. When I spend some time thinking about a good way to write it in Haskell, it's guiding me toward a better understanding of the problem itself that would potentially be helpful no matter what language I'm using. But using Haskell provides the impetus for this thinking. Dennis -------------- next part -------------- An HTML attachment was scrubbed... URL: From dennis.raddle at gmail.com Fri Nov 27 13:56:18 2015 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Fri, 27 Nov 2015 05:56:18 -0800 Subject: [Haskell-beginners] comment on this debugging trick? Message-ID: When I design my code, I am aware of the properties I expect my internal data representations to have, or I want input data to conform to my expectations. For example, right now I'm writing code that reads MusicXML. MusicXML is a crazy language, way too complicated for what it does, and the music typesetters that export MusicXML all do their own idiosyncratic things with it. I'm only reading the output of one typesetter, Sibelius, and although I don't know the internals of Sibelius, I can make some assumptions about what it's going to produce by a few examples, plus my application doesn't use the full range of MusicXML. I don't need to handle every case, is what I'm getting at. However, if I should have been wrong about my assumptions when I wrote the code, I don't want my program to behave erratically. I want to find out exactly what went wrong as soon as possible. Previously, I was including a lot of exception throwing, with each exception having a unique message describing what had happened, and in particular describing where in the code it is located so I can find the problem spot If I throw generic error messages like "Error: problem parsing" and I have many of those located in the code, I need the debugger to find it. Same if I use things like "fromJust" or "head" I haven't had good experiences using the debugger. Maybe that's my fault, but I like that I can locate my unique exceptions and that they are descriptive. But a month ago I decided this system is pretty ugly. It bloats the code a lot, and requires writing a lot of messages for situations that will probably never occur. I am trying a different method now. I write the code so that surprising behavior will result in a case or pattern exhaustion, which produces a run time message with a file name and line number. I'm not sure why ghc gives the location for a case exhaustion, but not something like "head". For example, instead of using head xs I can write x = case xs of {y:_ -> y} This is a little bloat but not too bad. Most of the time I'm actually structuring cases and patterns, and it actually helps me to simplify code to think of how to write it with the fewest cases and so that a case exhaustion will indicate something pretty specific. Any comments welcome. -------------- next part -------------- An HTML attachment was scrubbed... URL: From syrion at gmail.com Fri Nov 27 15:17:38 2015 From: syrion at gmail.com (Blake Hyde) Date: Fri, 27 Nov 2015 10:17:38 -0500 Subject: [Haskell-beginners] is Haskell practical? In-Reply-To: References: <5655AFEA.4020700@plaimi.net> <5655F4CF.9000807@vlkk.cz> Message-ID: On Fri, Nov 27, 2015 at 8:17 AM, Dennis Raddle wrote: > > Martin, > > One issue I can foresee is having both good Haskell programmers and > non-creative Haskell programmers on the same team. The good ones can easily > write code that is incomprehensible to the non-creative ones. > > It actually happened in my team twice that C++ code was thrown out and > assigned to someone else for a complete rewrite, because the senior > software engineer deemed that the original code was incomprehensible. In > both cases it was code that used a few tricks that I think were good, and > in both cases the replacement code was buggier. > > This is not unique to Haskell; this is a problem with programming in general. People with more ability can write code that is clean, fast, and easy to read, but which "average" programmers find confusing. I don't think it's realistic to avoid that in any language; I've even had people review my Ruby code that used the "Hash[]" constructor to build a hashmap from a list and call that confusing. > > Very well put. I didn't really think about what meant by "practical," and > it depends on context. > > I am gaining some Haskell momentum, and I see how the potential for > conciseness seems to encourage the kind of thinking about a problem that > leads to simplifications and optimizations. When I spend some time thinking > about a good way to write it in Haskell, it's guiding me toward a better > understanding of the problem itself that would potentially be helpful no > matter what language I'm using. But using Haskell provides the impetus for > this thinking. > > In my opinion, thinking about the problem up front is the most vital aspect of writing reliable, readable code, in any language. Haskell allows you to encode those insights into the types; in other languages, they frequently live only in your short term memory (or, if you're particularly conscientious, docstrings--although those are neglected the minute anyone else touches them). -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeffbrown.the at gmail.com Fri Nov 27 18:31:47 2015 From: jeffbrown.the at gmail.com (Jeffrey Brown) Date: Fri, 27 Nov 2015 10:31:47 -0800 Subject: [Haskell-beginners] comment on this debugging trick? In-Reply-To: References: Message-ID: Elliot Cameron, very smart guy, once advised me to make illegal state invalid. Jake Brownson, another, recommended trying to use Maybes and Eithers instead of throwing exceptions. I'm having trouble coming up with examples but I think they're both helpful. That said, your trick of replacing, for instance, head with a case statement seems good to me ... On Fri, Nov 27, 2015 at 5:56 AM, Dennis Raddle wrote: > When I design my code, I am aware of the properties I expect my internal > data representations to have, or I want input data to conform to my > expectations. For example, right now I'm writing code that reads MusicXML. > MusicXML is a crazy language, way too complicated for what it does, and the > music typesetters that export MusicXML all do their own idiosyncratic > things with it. I'm only reading the output of one typesetter, Sibelius, > and although I don't know the internals of Sibelius, I can make some > assumptions about what it's going to produce by a few examples, plus my > application doesn't use the full range of MusicXML. I don't need to handle > every case, is what I'm getting at. > > However, if I should have been wrong about my assumptions when I wrote the > code, I don't want my program to behave erratically. I want to find out > exactly what went wrong as soon as possible. > > Previously, I was including a lot of exception throwing, with each > exception having a unique message describing what had happened, and in > particular describing where in the code it is located so I can find the > problem spot > > If I throw generic error messages like "Error: problem parsing" and I have > many of those located in the code, I need the debugger to find it. Same if > I use things like "fromJust" or "head" > > I haven't had good experiences using the debugger. Maybe that's my fault, > but I like that I can locate my unique exceptions and that they are > descriptive. > > But a month ago I decided this system is pretty ugly. It bloats the code a > lot, and requires writing a lot of messages for situations that will > probably never occur. > > I am trying a different method now. I write the code so that surprising > behavior will result in a case or pattern exhaustion, which produces a run > time message with a file name and line number. I'm not sure why ghc gives > the location for a case exhaustion, but not something like "head". > > For example, instead of using head xs I can write > > x = case xs of {y:_ -> y} > > This is a little bloat but not too bad. Most of the time I'm actually > structuring cases and patterns, and it actually helps me to simplify code > to think of how to write it with the fewest cases and so that a case > exhaustion will indicate something pretty specific. > > Any comments welcome. > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Jeffrey Benjamin Brown -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Fri Nov 27 19:05:58 2015 From: toad3k at gmail.com (David McBride) Date: Fri, 27 Nov 2015 14:05:58 -0500 Subject: [Haskell-beginners] comment on this debugging trick? In-Reply-To: References: Message-ID: If you compile with -prof you can use the traceStack function from Debug.Trace. That's something. On Fri, Nov 27, 2015 at 8:56 AM, Dennis Raddle wrote: > When I design my code, I am aware of the properties I expect my internal > data representations to have, or I want input data to conform to my > expectations. For example, right now I'm writing code that reads MusicXML. > MusicXML is a crazy language, way too complicated for what it does, and the > music typesetters that export MusicXML all do their own idiosyncratic > things with it. I'm only reading the output of one typesetter, Sibelius, > and although I don't know the internals of Sibelius, I can make some > assumptions about what it's going to produce by a few examples, plus my > application doesn't use the full range of MusicXML. I don't need to handle > every case, is what I'm getting at. > > However, if I should have been wrong about my assumptions when I wrote the > code, I don't want my program to behave erratically. I want to find out > exactly what went wrong as soon as possible. > > Previously, I was including a lot of exception throwing, with each > exception having a unique message describing what had happened, and in > particular describing where in the code it is located so I can find the > problem spot > > If I throw generic error messages like "Error: problem parsing" and I have > many of those located in the code, I need the debugger to find it. Same if > I use things like "fromJust" or "head" > > I haven't had good experiences using the debugger. Maybe that's my fault, > but I like that I can locate my unique exceptions and that they are > descriptive. > > But a month ago I decided this system is pretty ugly. It bloats the code a > lot, and requires writing a lot of messages for situations that will > probably never occur. > > I am trying a different method now. I write the code so that surprising > behavior will result in a case or pattern exhaustion, which produces a run > time message with a file name and line number. I'm not sure why ghc gives > the location for a case exhaustion, but not something like "head". > > For example, instead of using head xs I can write > > x = case xs of {y:_ -> y} > > This is a little bloat but not too bad. Most of the time I'm actually > structuring cases and patterns, and it actually helps me to simplify code > to think of how to write it with the fewest cases and so that a case > exhaustion will indicate something pretty specific. > > Any comments welcome. > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hjgtuyl at chello.nl Fri Nov 27 19:34:12 2015 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Fri, 27 Nov 2015 20:34:12 +0100 Subject: [Haskell-beginners] is Haskell practical? In-Reply-To: References: Message-ID: On Wed, 25 Nov 2015 13:37:30 +0100, Dennis Raddle wrote: : > But what if someone came along and said, "Well, conciseness isn't all > that > important. Having to type more isn't much of a drawback -- it doesn't > really increase the time it takes to write a program once you consider > that > there is a greater time spent in requirements collection, overall design, > debugging, and documentation. The real drawback of concise/expressive > Haskell is the difficulty in understanding and using it fluently. > Ultimately Haskell is just mathematicians having fun, but not very > practical." It is not just the amount of work with the keyboard; it also takes more time thinking about details if you don't have the conciseness of Haskell. More necessary thinking and typing leads to more bugs, software engineering books talk about the number of bugs per 1000 lines of code being constant, independent of the level of the language. Take for instance the memory allocation in C: - you have to remember which macro you defined for the buffer size - check your input if it doesn't overflow your buffer - remember to free the memory at the right point(s) in your program - check that you don't use the pointer after the buffer has been freed The automatic memory allocation in Haskell doesn't just save you the typing for allocation and freeing, it saves a lot of thinking and checking. It prevents a lot of bugs and therefore, it saves testing and debugging time. Similar things can be said about other things that make Haskell programs more compact. There are other advantages when using Haskell, e.g. - better modularity, see the paper "Why functional programming matters"[0] - guaranteed pure functions make it easier to reason about the code. You can find more at the Haskell site[1]. Regards, Henk-Jan van Tuyl [0] http://www.cse.chalmers.se/~rjmh/Papers/whyfp.pdf [1] https://wiki.haskell.org/Introduction#What.27s_good_about_functional_programming.3F -- 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/ From dennis.raddle at gmail.com Fri Nov 27 20:51:02 2015 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Fri, 27 Nov 2015 12:51:02 -0800 Subject: [Haskell-beginners] comment on this debugging trick? In-Reply-To: References: Message-ID: On Fri, Nov 27, 2015 at 10:31 AM, Jeffrey Brown wrote: > Elliot Cameron, very smart guy, once advised me to make illegal state > invalid. Jake Brownson, another, recommended trying to use Maybes and > Eithers instead of throwing exceptions. I'm having trouble coming up with > examples but I think they're both helpful. > > I think I know roughly what you are talking about, but there are places where unexpected input might result in something like an empty list. Suppose I need the head of that list under normal conditions. Maybe the list is produced by library code so I can't alter the data structures. That's the kind of situation I want to identify precisely and immediately. D -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeffbrown.the at gmail.com Fri Nov 27 22:51:45 2015 From: jeffbrown.the at gmail.com (Jeffrey Brown) Date: Fri, 27 Nov 2015 14:51:45 -0800 Subject: [Haskell-beginners] comment on this debugging trick? In-Reply-To: References: Message-ID: In parsing libraries for Haskell the "parse" function (or its equivalent) typically returns an Either. For instance there's parse :: Stream s Identity t => Parsec s () a -> SourceName -> s -> Either ParseError a in Text.Parsec.Prim. This is an example of making invalid state impossible. parse could return a list of all possible parses, with the empty list signifying that parsing failed. But by using an Either, the case of failure can be distinguished as a Left. Haskell will know to treat the Left differently, and if you need an error report, that left can bubble (through multiple Either-returning functions, with some handy do-notation) up to the user without ever invoking an exception to the ordinary control flow. On Fri, Nov 27, 2015 at 12:51 PM, Dennis Raddle wrote: > > > On Fri, Nov 27, 2015 at 10:31 AM, Jeffrey Brown > wrote: > >> Elliot Cameron, very smart guy, once advised me to make illegal state >> invalid. Jake Brownson, another, recommended trying to use Maybes and >> Eithers instead of throwing exceptions. I'm having trouble coming up with >> examples but I think they're both helpful. >> >> > I think I know roughly what you are talking about, but there are places > where unexpected input might result in something like an empty list. > Suppose I need the head of that list under normal conditions. Maybe the > list is produced by library code so I can't alter the data structures. > That's the kind of situation I want to identify precisely and immediately. > > D > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Jeffrey Benjamin Brown -------------- next part -------------- An HTML attachment was scrubbed... URL: From dennis.raddle at gmail.com Fri Nov 27 23:55:07 2015 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Fri, 27 Nov 2015 15:55:07 -0800 Subject: [Haskell-beginners] comment on this debugging trick? In-Reply-To: References: Message-ID: On Fri, Nov 27, 2015 at 2:51 PM, Jeffrey Brown wrote: > In parsing libraries for Haskell the "parse" function (or its equivalent) > typically returns an Either. For instance there's > > parse :: Stream > > s Identity > t > => Parsec > s > () a -> SourceName > -> > s -> Either > > ParseError > > a > > in Text.Parsec.Prim. This is an example of making invalid state > impossible. parse could return a list of all possible parses, with the > empty list signifying that parsing failed. But by using an Either, the case > of failure can be distinguished as a Left. Haskell will know to treat the > Left differently, and if you need an error report, that left can bubble > (through multiple Either-returning functions, with some handy do-notation) > up to the user without ever invoking an exception to the ordinary control > flow. > I've used the Either monad for exception handling. Yes, I was using do notation. This current project is just for myself. Exceptions represent either bugs or malformed input. I can catch some of them in the IO monad so my program prints an error but keeps running and lets me try again. If the program crashes out, no big problem. I'm parsing MusicXML with Text.XML.Light. The XML is always well-formed. However *MusicXML* is not a well-defined language. Like, does every element have a child element called ? No guarantee I can find, yet it has been true in the examples I've tried with the only typesetter I'm using to generate MusicXML. I can get my program running quickly without bothering with the case that is absent. But if that case someday occurs, I want to know precisely and immediately. Yet I don't want to write a detailed error message for every violated assumption, of which there are dozens necessary. So my solution is to find these things with case exhaustions. The program crashes and I have to inspect the code, but no problem. D -------------- next part -------------- An HTML attachment was scrubbed... URL: From stephen.tetley at gmail.com Sat Nov 28 10:14:03 2015 From: stephen.tetley at gmail.com (Stephen Tetley) Date: Sat, 28 Nov 2015 10:14:03 +0000 Subject: [Haskell-beginners] comment on this debugging trick? In-Reply-To: References: Message-ID: Hi Dennis For this use case I would make a small, general parser combinator library / monad on top of XML.Light, then use the new parser combinators to make a specialized parser for your subset MusicXML. The common parser combinator libraries (Parsec, Attoparsec, ...) can't be used with XML.Light because their mechanics are consuming an input stream whereas processing XML (or JSON) is moving a cursor through a tree, but the common API provided by parser combinator libraries can be re-used productively for a tree (cursor) parser. As well as moving the cursor, the custom parser monad can handle errors and backtracking if needed. Best wishes Stephen On 27 November 2015 at 23:55, Dennis Raddle wrote: > > [snip] > > > I've used the Either monad for exception handling. Yes, I was using do > notation. This current project is just for myself. Exceptions represent > either bugs or malformed input. I can catch some of them in the IO monad so > my program prints an error but keeps running and lets me try again. If the > program crashes out, no big problem. > > I'm parsing MusicXML with Text.XML.Light. The XML is always well-formed. > However *MusicXML* is not a well-defined language. Like, does every > element have a child element called ? No guarantee I can find, yet it > has been true in the examples I've tried with the only typesetter I'm using > to generate MusicXML. I can get my program running quickly without > bothering with the case that is absent. But if that case someday > occurs, I want to know precisely and immediately. Yet I don't want to write > a detailed error message for every violated assumption, of which there are > dozens necessary. So my solution is to find these things with case > exhaustions. The program crashes and I have to inspect the code, but no > problem. > From ondra at nekola.cz Sat Nov 28 15:41:10 2015 From: ondra at nekola.cz (Ondrej Nekola) Date: Sat, 28 Nov 2015 16:41:10 +0100 Subject: [Haskell-beginners] REPL with visualisation In-Reply-To: <56581ED2.8080101@nekola.cz> References: <56581ED2.8080101@nekola.cz> Message-ID: <5659CB16.4050809@nekola.cz> I can (partially) answer myself: after a bit of experimenting iHaskell (jupyter/ipython + haskell kernel - don't try to install this with cabal, stack works. Don't forget to install native libraries) is quite usable. There is great looking haskellformac (paid) software but as the name suggests it's OS X only. OSN > Hi > Just curious: is there some recommended "first choice" combination of > REPL and libs for (Apple) Swift styled "playgrounds"? (I have just > seen a fractalish coffee spill and remembered that I have not > implemented Mandelbrot set since high school and Pascal days and maybe > it's time to be a bit childish again). > Thanks > Ondra 'satai' Nekola > ondra at nekola.cz > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From objitsu at gmail.com Sat Nov 28 16:02:32 2015 From: objitsu at gmail.com (emacstheviking) Date: Sat, 28 Nov 2015 16:02:32 +0000 Subject: [Haskell-beginners] REPL with visualisation In-Reply-To: <5659CB16.4050809@nekola.cz> References: <56581ED2.8080101@nekola.cz> <5659CB16.4050809@nekola.cz> Message-ID: When I was learning it (still learning!) I just use emacs. Top half is my code window, bottom half is a standard "M-x shell" then run ghci. It works. I've tried to use leksah but it is a little "busy" and doesn't really help to keep things simple when you are still learning, IMO anyway. On 28 November 2015 at 15:41, Ondrej Nekola wrote: > I can (partially) answer myself: after a bit of experimenting iHaskell > (jupyter/ipython + haskell kernel - don't try to install this with cabal, > stack works. Don't forget to install native libraries) is quite usable. > There is great looking haskellformac (paid) software but as the name > suggests it's OS X only. > OSN > > > Hi >> Just curious: is there some recommended "first choice" combination of >> REPL and libs for (Apple) Swift styled "playgrounds"? (I have just seen a >> fractalish coffee spill and remembered that I have not implemented >> Mandelbrot set since high school and Pascal days and maybe it's time to be >> a bit childish again). >> Thanks >> Ondra 'satai' Nekola >> ondra at nekola.cz >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ondra at nekola.cz Sat Nov 28 16:10:02 2015 From: ondra at nekola.cz (Ondrej Nekola) Date: Sat, 28 Nov 2015 17:10:02 +0100 Subject: [Haskell-beginners] REPL with visualisation In-Reply-To: References: <56581ED2.8080101@nekola.cz> <5659CB16.4050809@nekola.cz> Message-ID: <5659D1DA.8090008@nekola.cz> Does it have some support for visual results or just text outputs? OSN > When I was learning it (still learning!) I just use emacs. > > Top half is my code window, bottom half is a standard "M-x shell" then > run ghci. It works. I've tried to use leksah but it is a little "busy" > and doesn't really help to keep things simple when you are still > learning, IMO anyway. > > > On 28 November 2015 at 15:41, Ondrej Nekola > wrote: > > I can (partially) answer myself: after a bit of experimenting > iHaskell (jupyter/ipython + haskell kernel - don't try to install > this with cabal, stack works. Don't forget to install native > libraries) is quite usable. There is great looking haskellformac > (paid) software but as the name suggests it's OS X only. > OSN > > > Hi > Just curious: is there some recommended "first choice" > combination of REPL and libs for (Apple) Swift styled > "playgrounds"? (I have just seen a fractalish coffee spill and > remembered that I have not implemented Mandelbrot set since > high school and Pascal days and maybe it's time to be a bit > childish again). > Thanks > Ondra 'satai' Nekola > ondra at nekola.cz > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Sat Nov 28 16:45:36 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Sat, 28 Nov 2015 22:15:36 +0530 Subject: [Haskell-beginners] REPL with visualisation In-Reply-To: <5659D1DA.8090008@nekola.cz> References: <56581ED2.8080101@nekola.cz> <5659CB16.4050809@nekola.cz> <5659D1DA.8090008@nekola.cz> Message-ID: For emacs, the integrated REPL support in haskell-mode is pretty good. The github wiki for haskell-mode gives a nice comprehensive overview of the features: https://github.com/haskell/haskell-mode/wiki/Haskell-Interactive-Mode On 28 November 2015 at 21:40, Ondrej Nekola wrote: > Does it have some support for visual results or just text outputs? > OSN > > When I was learning it (still learning!) I just use emacs. > > Top half is my code window, bottom half is a standard "M-x shell" then run > ghci. It works. I've tried to use leksah but it is a little "busy" and > doesn't really help to keep things simple when you are still learning, IMO > anyway. > > > On 28 November 2015 at 15:41, Ondrej Nekola wrote: > >> I can (partially) answer myself: after a bit of experimenting iHaskell >> (jupyter/ipython + haskell kernel - don't try to install this with cabal, >> stack works. Don't forget to install native libraries) is quite usable. >> There is great looking haskellformac (paid) software but as the name >> suggests it's OS X only. >> OSN >> >> >> Hi >>> Just curious: is there some recommended "first choice" combination of >>> REPL and libs for (Apple) Swift styled "playgrounds"? (I have just seen a >>> fractalish coffee spill and remembered that I have not implemented >>> Mandelbrot set since high school and Pascal days and maybe it's time to be >>> a bit childish again). >>> Thanks >>> Ondra 'satai' Nekola >>> ondra at nekola.cz >>> >> > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From objitsu at gmail.com Sat Nov 28 17:06:12 2015 From: objitsu at gmail.com (emacstheviking) Date: Sat, 28 Nov 2015 17:06:12 +0000 Subject: [Haskell-beginners] REPL with visualisation In-Reply-To: <5659D1DA.8090008@nekola.cz> References: <56581ED2.8080101@nekola.cz> <5659CB16.4050809@nekola.cz> <5659D1DA.8090008@nekola.cz> Message-ID: Ondrej, It has just text. Have you seen this though...? The hackage page... https://hackage.haskell.org/package/vacuum and a YouTube video... https://www.youtube.com/watch?v=X4-212uMgy8 That might be of interest?! All the best, Sean. On 28 November 2015 at 16:10, Ondrej Nekola wrote: > Does it have some support for visual results or just text outputs? > OSN > > When I was learning it (still learning!) I just use emacs. > > Top half is my code window, bottom half is a standard "M-x shell" then run > ghci. It works. I've tried to use leksah but it is a little "busy" and > doesn't really help to keep things simple when you are still learning, IMO > anyway. > > > On 28 November 2015 at 15:41, Ondrej Nekola wrote: > >> I can (partially) answer myself: after a bit of experimenting iHaskell >> (jupyter/ipython + haskell kernel - don't try to install this with cabal, >> stack works. Don't forget to install native libraries) is quite usable. >> There is great looking haskellformac (paid) software but as the name >> suggests it's OS X only. >> OSN >> >> >> Hi >>> Just curious: is there some recommended "first choice" combination of >>> REPL and libs for (Apple) Swift styled "playgrounds"? (I have just seen a >>> fractalish coffee spill and remembered that I have not implemented >>> Mandelbrot set since high school and Pascal days and maybe it's time to be >>> a bit childish again). >>> Thanks >>> Ondra 'satai' Nekola >>> ondra at nekola.cz >>> >> > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin at vlkk.cz Sat Nov 28 17:26:58 2015 From: martin at vlkk.cz (Martin Vlk) Date: Sat, 28 Nov 2015 17:26:58 +0000 Subject: [Haskell-beginners] REPL with visualisation In-Reply-To: References: <56581ED2.8080101@nekola.cz> <5659CB16.4050809@nekola.cz> <5659D1DA.8090008@nekola.cz> Message-ID: <5659E3E2.2040605@vlkk.cz> Great to hear people still play with programming - I should do that more myself! ;-) Racket has a very nice REPL that lets you display nontextual data, such as the plot utils for graphs here: http://docs.racket-lang.org/plot/utils.html Would be great to get something like this for Haskell. Otherwise for the Mandelbrot set I'd imagine you could use the "diagrams" package to specify the graphics using Haskell and then have it rendered into a file that you load up into browser. Then you can change the spec, re-generate file and reload in the browser. M. emacstheviking: > Ondrej, > > It has just text. Have you seen this though...? > > The hackage page... > > https://hackage.haskell.org/package/vacuum > > and a YouTube video... > > https://www.youtube.com/watch?v=X4-212uMgy8 > > That might be of interest?! > > All the best, > Sean. > > > > > On 28 November 2015 at 16:10, Ondrej Nekola > wrote: > > Does it have some support for visual results or just text outputs? > OSN > >> When I was learning it (still learning!) I just use emacs. >> >> Top half is my code window, bottom half is a standard "M-x shell" >> then run ghci. It works. I've tried to use leksah but it is a >> little "busy" and doesn't really help to keep things simple when >> you are still learning, IMO anyway. >> >> >> On 28 November 2015 at 15:41, Ondrej Nekola > > wrote: >> >> I can (partially) answer myself: after a bit of experimenting >> iHaskell (jupyter/ipython + haskell kernel - don't try to >> install this with cabal, stack works. Don't forget to install >> native libraries) is quite usable. There is great looking >> haskellformac (paid) software but as the name suggests it's OS >> X only. >> OSN >> >> >> Hi >> Just curious: is there some recommended "first choice" >> combination of REPL and libs for (Apple) Swift styled >> "playgrounds"? (I have just seen a fractalish coffee spill >> and remembered that I have not implemented Mandelbrot set >> since high school and Pascal days and maybe it's time to >> be a bit childish again). >> Thanks >> Ondra 'satai' Nekola >> ondra at nekola.cz >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From jeffbrown.the at gmail.com Sat Nov 28 17:58:44 2015 From: jeffbrown.the at gmail.com (Jeffrey Brown) Date: Sat, 28 Nov 2015 09:58:44 -0800 Subject: [Haskell-beginners] comment on this debugging trick? In-Reply-To: References: Message-ID: > (Parsec, Attoparsec, ...) can't > be used with XML.Light because their mechanics are consuming > an input stream whereas processing XML (or JSON) is > moving a cursor through a tree Stephen, the "consuming an input vs. moving a cursor through a tree" distinction you're drawing is unclear to me. Can you elaborate, or provide references? Also, Text.JSON.Parsec [1] would appear to be a counterexample to your claim. [1] https://hackage.haskell.org/package/json-0.9.1/docs/Text-JSON-Parsec.html On Sat, Nov 28, 2015 at 2:14 AM, Stephen Tetley wrote: > Hi Dennis > > For this use case I would make a small, general parser combinator > library / monad on top of XML.Light, then use the new parser > combinators to make a specialized parser for your subset MusicXML. > > The common parser combinator libraries (Parsec, Attoparsec, ...) can't > be used with XML.Light because their mechanics are consuming an input > stream whereas processing XML (or JSON) is moving a cursor through a > tree, but the common API provided by parser combinator libraries can > be re-used productively for a tree (cursor) parser. As well as moving > the cursor, the custom parser monad can handle errors and backtracking > if needed. > > Best wishes > > Stephen > > On 27 November 2015 at 23:55, Dennis Raddle > wrote: > > > > > [snip] > > > > > > I've used the Either monad for exception handling. Yes, I was using do > > notation. This current project is just for myself. Exceptions represent > > either bugs or malformed input. I can catch some of them in the IO monad > so > > my program prints an error but keeps running and lets me try again. If > the > > program crashes out, no big problem. > > > > I'm parsing MusicXML with Text.XML.Light. The XML is always well-formed. > > However *MusicXML* is not a well-defined language. Like, does every > > > element have a child element called ? No guarantee I can find, > yet it > > has been true in the examples I've tried with the only typesetter I'm > using > > to generate MusicXML. I can get my program running quickly without > > bothering with the case that is absent. But if that case someday > > occurs, I want to know precisely and immediately. Yet I don't want to > write > > a detailed error message for every violated assumption, of which there > are > > dozens necessary. So my solution is to find these things with case > > exhaustions. The program crashes and I have to inspect the code, but no > > problem. > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Jeffrey Benjamin Brown -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark.fine at gmail.com Sat Nov 28 22:52:24 2015 From: mark.fine at gmail.com (Mark Fine) Date: Sat, 28 Nov 2015 14:52:24 -0800 Subject: [Haskell-beginners] REPL with visualisation In-Reply-To: <56581ED2.8080101@nekola.cz> References: <56581ED2.8080101@nekola.cz> Message-ID: I think that's the approach Haskell for Mac is taking: http://haskellformac.com/ http://blog.haskellformac.com/blog/fractals-recursion-in-pictures http://learn.hfm.io/fractals.html Mark On Fri, Nov 27, 2015 at 1:13 AM, Ondrej Nekola wrote: > Hi > Just curious: is there some recommended "first choice" combination of REPL > and libs for (Apple) Swift styled "playgrounds"? (I have just seen a > fractalish coffee spill and remembered that I have not implemented > Mandelbrot set since high school and Pascal days and maybe it's time to be > a bit childish again). > Thanks > Ondra 'satai' Nekola > ondra at nekola.cz > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stephen.tetley at gmail.com Sun Nov 29 00:31:54 2015 From: stephen.tetley at gmail.com (Stephen Tetley) Date: Sun, 29 Nov 2015 00:31:54 +0000 Subject: [Haskell-beginners] comment on this debugging trick? In-Reply-To: References: Message-ID: Hi Jeffrey The example you linked to is a JSON parser written with Parsec - it takes an input stream of characters and returns a JSON tree. To go from "uni-typed" JSON to Haskell data represented by your domain datatypes you have to do further conversion. This conversion is from "tree to tree" rather than "from input stream to tree". If the correspondence between the JSON (or XML) is one-to-one you can do a fairly mechanical deserialization (I think some of the libraries already have Template Haskell processors for this). In Dennis's case he wants to go from a very large XML representation to deal with a more manageable subset in Haskell and believes that the input he works with always belongs to the manageable subset. To get from MusicXML's large tree - represented again by a uni-typed tree in XML.Light - parser combinators provide a fine API for the job but the internal machinary needs to be able to traverse a tree (descend child nodes, climb back out on failure etc.) rather than consume an input stream. On 28 November 2015 at 17:58, Jeffrey Brown wrote: >> (Parsec, Attoparsec, ...) can't >> be used with XML.Light because their mechanics are consuming >> an input stream whereas processing XML (or JSON) is >> moving a cursor through a tree > > Stephen, the "consuming an input vs. moving a cursor through a tree" > distinction you're drawing is unclear to me. Can you elaborate, or provide > references? > > Also, Text.JSON.Parsec [1] would appear to be a counterexample to your > claim. > > [1] > https://hackage.haskell.org/package/json-0.9.1/docs/Text-JSON-Parsec.html From jykang22 at gmail.com Sun Nov 29 02:42:58 2015 From: jykang22 at gmail.com (Jeon-Young Kang) Date: Sat, 28 Nov 2015 21:42:58 -0500 Subject: [Haskell-beginners] Anyone suggest .csv file parser? Message-ID: Hi all. I am working on import *.csv file into haskell. As you guys recommended, I built code for comparison human's age as follows. data Person = Person {name:: String, age:: Int } deriving(Show) data Relations = Friend | Older | Younger class Comparison a where compare:: a -> a -> Relations instance Comparison Person where compare (Person a b) (Person a b) | b1 == b2 = Friend | b1 > b2 = Older | b1 < b2 = Younger Also, I have .csv file as follows. name age tom 19 jane 21 By using above code, I would like to apply the above code for .csv file. What is the best for this purpose? Sincerely, JY -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Sun Nov 29 02:54:36 2015 From: fa-ml at ariis.it (Francesco Ariis) Date: Sun, 29 Nov 2015 03:54:36 +0100 Subject: [Haskell-beginners] Anyone suggest .csv file parser? In-Reply-To: References: Message-ID: <20151129025436.GA18700@casa.casa> On Sat, Nov 28, 2015 at 09:42:58PM -0500, Jeon-Young Kang wrote: > Hi all. > > I am working on import *.csv file into haskell. > > [..] > > What is the best for this purpose? I use http://hackage.haskell.org/package/csv and never had troubles with it. `parseCSV` returns a list of lists ([[String]]) which is easy enough to manipulate for whatever you need. From dennis.raddle at gmail.com Sun Nov 29 08:02:51 2015 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Sun, 29 Nov 2015 00:02:51 -0800 Subject: [Haskell-beginners] comment on this debugging trick? In-Reply-To: References: Message-ID: On Sat, Nov 28, 2015 at 2:14 AM, Stephen Tetley wrote: > Hi Dennis > > For this use case I would make a small, general parser combinator > library / monad on top of XML.Light, then use the new parser > combinators to make a specialized parser for your subset MusicXML. > > The common parser combinator libraries (Parsec, Attoparsec, ...) can't > be used with XML.Light because their mechanics are consuming an input > stream whereas processing XML (or JSON) is moving a cursor through a > tree, but the common API provided by parser combinator libraries can > be re-used productively for a tree (cursor) parser. As well as moving > the cursor, the custom parser monad can handle errors and backtracking > if needed. > > Thanks for the pointers, Stephen. I will look into it. I don't know if I'll have time to learn how to do this though. I'll keep it in mind for the future. This is a small, ongoing, no-pressure project, which is even lower pressure when you consider I'm using what I call "just in time" debugging and design. When I look at my use cases, I don't implement any that seem unlikely. If they ever do occur, I can deal with them then. But I don't just ignore cases willy-nilly -- I always consider if they do occur, that the resulting bug will be obvious right away and lead me directly to the answer. This is interesting when dealing with music playback. Some unexpected cases won't give an error message but will affect the playback sound -- so I always ask myself, "Will this bug be obvious, really screw up the sound in a major way, so I know it's happening?" Because what I don't want are bugs that create small effects that I might miss for a while so I miss the critical moment they were introduced. I don't know the definition of the different processes but does "Just In Time" design/debugging have something to do with Agile? D -------------- next part -------------- An HTML attachment was scrubbed... URL: From ryan.trinkle at gmail.com Sun Nov 29 09:07:23 2015 From: ryan.trinkle at gmail.com (Ryan Trinkle) Date: Sun, 29 Nov 2015 04:07:23 -0500 Subject: [Haskell-beginners] Anyone suggest .csv file parser? In-Reply-To: <20151129025436.GA18700@casa.casa> References: <20151129025436.GA18700@casa.casa> Message-ID: I'd recommend taking a look at cassava . On Sat, Nov 28, 2015 at 9:54 PM, Francesco Ariis wrote: > On Sat, Nov 28, 2015 at 09:42:58PM -0500, Jeon-Young Kang wrote: > > Hi all. > > > > I am working on import *.csv file into haskell. > > > > [..] > > > > What is the best for this purpose? > > I use http://hackage.haskell.org/package/csv and never had troubles > with it. `parseCSV` returns a list of lists ([[String]]) which is > easy enough to manipulate for whatever you need. > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jykang22 at gmail.com Sun Nov 29 19:48:33 2015 From: jykang22 at gmail.com (Jeon-Young Kang) Date: Sun, 29 Nov 2015 14:48:33 -0500 Subject: [Haskell-beginners] Anyone suggest .csv file parser? In-Reply-To: References: <20151129025436.GA18700@casa.casa> Message-ID: Thanks for your recommendation. Now, I am looking through cassava. I just got to know how to import *.csv file to haskell. Then, if I need calculate something (summary, dividing, and so on), can you give me an example source code? Sincerely, On Sun, Nov 29, 2015 at 4:07 AM, Ryan Trinkle wrote: > I'd recommend taking a look at cassava > . > > On Sat, Nov 28, 2015 at 9:54 PM, Francesco Ariis wrote: > >> On Sat, Nov 28, 2015 at 09:42:58PM -0500, Jeon-Young Kang wrote: >> > Hi all. >> > >> > I am working on import *.csv file into haskell. >> > >> > [..] >> > >> > What is the best for this purpose? >> >> I use http://hackage.haskell.org/package/csv and never had troubles >> with it. `parseCSV` returns a list of lists ([[String]]) which is >> easy enough to manipulate for whatever you need. >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Department of Geography State University of New York at Buffalo jykang22 at gmail.com Jeon-Young Kang -------------- next part -------------- An HTML attachment was scrubbed... URL: