From hilco.wijbenga at gmail.com Mon Jul 2 20:03:07 2018 From: hilco.wijbenga at gmail.com (Hilco Wijbenga) Date: Mon, 2 Jul 2018 13:03:07 -0700 Subject: [Haskell-beginners] Design help to add imports to a (Java) template Message-ID: Hi all, I'm working on a Haskell (Eta) tool to generate Java ADTs. I have the following definitions: data Line = Line Int Text [JavaImport] -- The Int represents the indentation level of this line. data Template = None | One Line | Many [Line] | Template (Reader Configuration Template) I then run it like this (incomplete, I hope you get the idea): main :: IO () main = putStr $ replace (importsGoHereKey `append` "\n") importsAsText templateAsText where config = Configuration (Copyright 2018 "Me") USE_GETTERS point' = javaClassTemplate point importsAsText = runReader (mapReader javaImportsToText (javaImports point')) config templateAsText = runReader (toText tab point') config Essentially, I use the template twice: once to extract the Java imports and once to generate the result Text. Then I replace a magic string in the result Text with the import code. It works but makes me sad. ;-) I will probably pull out the JavaImport list from Line and use something like State to keep track of the necessary imports. (Now that I understand Reader, maybe State is no longer a bridge too far.) My main issue is how to avoid the magic string. I thought about adding an extra entry to Template [something like Imports ((Set JavaImport) -> Text or maybe Template)] but then I don't know how to implement "instance Monoid Template". Similarly if I use something Reader like. Any design advice or ideas would be appreciated. If it's of any help, the full code is at [1] (it's tiny). Any and all comments are welcome, by the way: I'm still a Haskell beginner. Cheers, Hilco [1] https://github.com/hilcode/java-algebraic-data-types From jeffbrown.the at gmail.com Wed Jul 4 11:10:56 2018 From: jeffbrown.the at gmail.com (Jeffrey Brown) Date: Wed, 4 Jul 2018 06:10:56 -0500 Subject: [Haskell-beginners] Where to report an unfriendly feature (if not a bug) in `stack ghci`? Message-ID: I don't know whether this is a problem with stack or with GHCI. But suppose you've got a bunch of modules loaded, and the prompt is hard to read, so you set it to something simpler like "> ". If you then use ":{" to enter a multi-line block of code, the module names appear again at the prompt, making the block you're entering very difficult to read. Here's an example: ) Ok, 55 modules loaded. Loaded GHCi configuration from /tmp/haskell-stack-ghci/d770186e/ghci-script *Vivid.UGens.UserInteraction Vivid Vivid.Actions Vivid.Actions.Class Vivid.Acti ons.IO Vivid.Actions.NRT Vivid.Actions.Scheduled Vivid.ByteBeat Vivid.Envelopes Vivid.NoPlugins Vivid.OSC Vivid.OSC.Util Vivid.Randomness Vivid.SCServer Vivid .SCServer.Connection Vivid.SCServer.State Vivid.SCServer.Types Vivid.SynthDef V ivid.SynthDef.FromUA Vivid.SynthDef.Literally Vivid.SynthDef.ToSig Vivid.SynthD ef.Types Vivid.SynthDef.TypesafeArgs Vivid.UGens Vivid.UGens.Algebraic Vivid.UG ens.Analysis Vivid.UGens.Args Vivid.UGens.Buffer Vivid.UGens.Conversion Vivid.U Gens.Convolution Vivid.UGens.Delays Vivid.UGens.Demand Vivid.UGens.Dynamics Viv id.UGens.Envelopes Vivid.UGens.Examples Vivid.UGens.FFT Vivid.UGens.Filters Viv id.UGens.Filters.BEQSuite Vivid.UGens.Filters.Linear Vivid.UGens.Filters.Nonlin ear Vivid.UGens.Filters.Pitch Vivid.UGens.Generators.Chaotic Vivid.UGens.Genera tors.Deterministic Vivid.UGens.Generators.Granular Vivid.UGens.Generators.Singl eValue Vivid.UGens.Generators.Stochastic Vivid.UGens.InOut Vivid.UGens.Info Viv id.UGens.Maths Vivid.UGens.Multichannel Vivid.UGens.Random Vivid.UGens.Reverbs Vivid.UGens.SynthControl Vivid.UGens.Triggers Vivid.UGens.Undocumented Vivid.UG ens.UserInteraction> :set prompt "> " > 3+1 4 > :{ *Vivid.UGens.UserInteraction Vivid Vivid.Actions Vivid.Actions.Class Vivid.Acti ons.IO Vivid.Actions.NRT Vivid.Actions.Scheduled Vivid.ByteBeat Vivid.Envelopes Vivid.NoPlugins Vivid.OSC Vivid.OSC.Util Vivid.Randomness Vivid.SCServer Vivid .SCServer.Connection Vivid.SCServer.State Vivid.SCServer.Types Vivid.SynthDef V ivid.SynthDef.FromUA Vivid.SynthDef.Literally Vivid.SynthDef.ToSig Vivid.SynthD ef.Types Vivid.SynthDef.TypesafeArgs Vivid.UGens Vivid.UGens.Algebraic Vivid.UG ens.Analysis Vivid.UGens.Args Vivid.UGens.Buffer Vivid.UGens.Conversion Vivid.U Gens.Convolution Vivid.UGens.Delays Vivid.UGens.Demand Vivid.UGens.Dynamics Viv id.UGens.Envelopes Vivid.UGens.Examples Vivid.UGens.FFT Vivid.UGens.Filters Viv id.UGens.Filters.BEQSuite Vivid.UGens.Filters.Linear Vivid.UGens.Filters.Nonlin ear Vivid.UGens.Filters.Pitch Vivid.UGens.Generators.Chaotic Vivid.UGens.Genera tors.Deterministic Vivid.UGens.Generators.Granular Vivid.UGens.Generators.Singl eValue Vivid.UGens.Generators.Stochastic Vivid.UGens.InOut Vivid.UGens.Info Viv id.UGens.Maths Vivid.UGens.Multichannel Vivid.UGens.Random Vivid.UGens.Reverbs Vivid.UGens.SynthControl Vivid.UGens.Triggers Vivid.UGens.Undocumented Vivid.UG ens.UserInteraction| f = let y = 3 *Vivid.UGens.UserInteraction Vivid Vivid.Actions Vivid.Actions.Class Vivid.Acti ons.IO Vivid.Actions.NRT Vivid.Actions.Scheduled Vivid.ByteBeat Vivid.Envelopes Vivid.NoPlugins Vivid.OSC Vivid.OSC.Util Vivid.Randomness Vivid.SCServer Vivid .SCServer.Connection Vivid.SCServer.State Vivid.SCServer.Types Vivid.SynthDef V ivid.SynthDef.FromUA Vivid.SynthDef.Literally Vivid.SynthDef.ToSig Vivid.SynthD ef.Types Vivid.SynthDef.TypesafeArgs Vivid.UGens Vivid.UGens.Algebraic Vivid.UG ens.Analysis Vivid.UGens.Args Vivid.UGens.Buffer Vivid.UGens.Conversion Vivid.U Gens.Convolution Vivid.UGens.Delays Vivid.UGens.Demand Vivid.UGens.Dynamics Viv id.UGens.Envelopes Vivid.UGens.Examples Vivid.UGens.FFT Vivid.UGens.Filters Viv id.UGens.Filters.BEQSuite Vivid.UGens.Filters.Linear Vivid.UGens.Filters.Nonlin ear Vivid.UGens.Filters.Pitch Vivid.UGens.Generators.Chaotic Vivid.UGens.Genera tors.Deterministic Vivid.UGens.Generators.Granular Vivid.UGens.Generators.Singl eValue Vivid.UGens.Generators.Stochastic Vivid.UGens.InOut Vivid.UGens.Info Viv id.UGens.Maths Vivid.UGens.Multichannel Vivid.UGens.Random Vivid.UGens.Reverbs Vivid.UGens.SynthControl Vivid.UGens.Triggers Vivid.UGens.Undocumented Vivid.UG ens.UserInteraction| in y + 1 *Vivid.UGens.UserInteraction Vivid Vivid.Actions Vivid.Actions.Class Vivid.Acti ons.IO Vivid.Actions.NRT Vivid.Actions.Scheduled Vivid.ByteBeat Vivid.Envelopes Vivid.NoPlugins Vivid.OSC Vivid.OSC.Util Vivid.Randomness Vivid.SCServer Vivid .SCServer.Connection Vivid.SCServer.State Vivid.SCServer.Types Vivid.SynthDef V ivid.SynthDef.FromUA Vivid.SynthDef.Literally Vivid.SynthDef.ToSig Vivid.SynthD ef.Types Vivid.SynthDef.TypesafeArgs Vivid.UGens Vivid.UGens.Algebraic Vivid.UG ens.Analysis Vivid.UGens.Args Vivid.UGens.Buffer Vivid.UGens.Conversion Vivid.U Gens.Convolution Vivid.UGens.Delays Vivid.UGens.Demand Vivid.UGens.Dynamics Viv id.UGens.Envelopes Vivid.UGens.Examples Vivid.UGens.FFT Vivid.UGens.Filters Viv id.UGens.Filters.BEQSuite Vivid.UGens.Filters.Linear Vivid.UGens.Filters.Nonlin ear Vivid.UGens.Filters.Pitch Vivid.UGens.Generators.Chaotic Vivid.UGens.Genera tors.Deterministic Vivid.UGens.Generators.Granular Vivid.UGens.Generators.Singl eValue Vivid.UGens.Generators.Stochastic Vivid.UGens.InOut Vivid.UGens.Info Viv id.UGens.Maths Vivid.UGens.Multichannel Vivid.UGens.Random Vivid.UGens.Reverbs Vivid.UGens.SynthControl Vivid.UGens.Triggers Vivid.UGens.Undocumented Vivid.UG ens.UserInteraction| :} > f 4 > -- Jeff Brown | Jeffrey Benjamin Brown Website | Facebook | LinkedIn (spammy, so I often miss messages here) | Github -------------- next part -------------- An HTML attachment was scrubbed... URL: From utprimum at gmail.com Wed Jul 4 12:30:47 2018 From: utprimum at gmail.com (Ut Primum) Date: Wed, 4 Jul 2018 14:30:47 +0200 Subject: [Haskell-beginners] Where to report an unfriendly feature (if not a bug) in `stack ghci`? In-Reply-To: References: Message-ID: Hi, I think the same was reported here: https://ghc.haskell.org/trac/ghc/ticket/7509#no1 Ut -------------- next part -------------- An HTML attachment was scrubbed... URL: From revollat at gmail.com Wed Jul 4 14:31:46 2018 From: revollat at gmail.com (Olivier Revollat) Date: Wed, 4 Jul 2018 16:31:46 +0200 Subject: [Haskell-beginners] Presentation Message-ID: Hi, I'm a french (any other french here ?) web developper since 2001. I use PHP, Python essentially and I've been working with Haskell for a few month now ... I really like it even if it's quite hard to start. I like the mathematical aspect of the language. So hello everyone ! -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Wed Jul 4 14:40:27 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Wed, 4 Jul 2018 16:40:27 +0200 Subject: [Haskell-beginners] Presentation In-Reply-To: References: Message-ID: <20180704144027.su3ntwuxxk4pzvsm@x60s.casa> On Wed, Jul 04, 2018 at 04:31:46PM +0200, Olivier Revollat wrote: > Hi, > I'm a french (any other french here ?) web developper since 2001. I use > PHP, Python essentially and I've been working with Haskell for a few month > now ... I really like it even if it's quite hard to start. I like the > mathematical aspect of the language. > So hello everyone ! Bienvenue Olivier & enjoy the journey :) From imantc at gmail.com Wed Jul 4 14:46:03 2018 From: imantc at gmail.com (Imants Cekusins) Date: Wed, 4 Jul 2018 17:46:03 +0300 Subject: [Haskell-beginners] Presentation In-Reply-To: References: Message-ID: Salut Olivier. Enjoy! :) On Wed, 4 Jul 2018 17:32 Olivier Revollat, wrote: > Hi, > I'm a french (any other french here ?) web developper since 2001. I use > PHP, Python essentially and I've been working with Haskell for a few month > now ... I really like it even if it's quite hard to start. I like the > mathematical aspect of the language. > So hello everyone ! > _______________________________________________ > 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 awsafrahman1704 at gmail.com Thu Jul 5 20:21:15 2018 From: awsafrahman1704 at gmail.com (Awsaf Rahman) Date: Thu, 5 Jul 2018 22:21:15 +0200 Subject: [Haskell-beginners] Passing a file containing a list as an input Message-ID: Hello everyone! I am really struggling with Haskell I/O. I have written a mergesort program and as an input to that program I want to use a file containing a list of 1000 integers. Let's say the contents of the file look like this [120, 400, 500 , 20, 100 ..] How can I achieve that? I am trying to write a main function that takes the file as an input and passes the list to my mergesort function.. Regards Awsaf Rahman -------------- next part -------------- An HTML attachment was scrubbed... URL: From to_br at uni-bremen.de Thu Jul 5 20:36:39 2018 From: to_br at uni-bremen.de (Tobias Brandt) Date: Thu, 05 Jul 2018 22:36:39 +0200 Subject: [Haskell-beginners] Passing a file containing a list as an input In-Reply-To: Message-ID: <20180705223639.Horde.XYA17XzozLb2eFl2SR-tzKN@webmail.uni-bremen.de> Hello Awsaf,  you should probably look further into the topic of "IO in Haskell" and "Monads". Then you can use impure functions like readFile (http://hackage.haskell.org/package/base-4.11.1.0/docs/Prelude.html#v:readFile ) or getArgs (http://hackage.haskell.org/package/base-4.11.1.0/docs/System-Environment.html#v:getArgs). A naive solution might look like this:    module Main where   import           System.Environment (getArgs)   main = do   (fileName:_) <- getArgs   unsortedList <- read <$> readFile fileName   let sorted = yourMergeSortFunction unsortedList   print sorted -- maybe you like to print your sorted list Best regards, Tobias ----- Nachricht von Awsaf Rahman ---------      Datum: Thu, 5 Jul 2018 22:21:15 +0200        Von: Awsaf Rahman Antwort an: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell    Betreff: [Haskell-beginners] Passing a file containing a list as an input         An: beginners at haskell.org > Hello everyone!    > I am really struggling with Haskell I/O.  >   > I have written a mergesort program and as an input to that > program I want to use a file containing a list of 1000 integers. > Let's say the contents of the file look like this >   > [120, 400, 500 , 20, 100 ..]  >   > How can I achieve that? I am trying to write a main function that > takes the file as an input and passes the list to my mergesort > function..  >   > Regards > Awsaf Rahman ----- Ende der Nachricht von Awsaf Rahman ----- -------------- next part -------------- An HTML attachment was scrubbed... URL: From awsafrahman1704 at gmail.com Fri Jul 6 02:01:27 2018 From: awsafrahman1704 at gmail.com (Awsaf Rahman) Date: Fri, 6 Jul 2018 04:01:27 +0200 Subject: [Haskell-beginners] Execution time of Mergesort Message-ID: Hello everyone! I am trying to find out the execution time of mergesort for a list size of 1 million integers. I have done the same in Erlang as well and the execution time in Erlang was around 0.93 seconds. I have implemented the program in almost the same way in Haskell as well but for some reason the Haskell implementation is taking around 12 seconds which doesn't seem right. Here is the implementation in Haskell: *{-# LANGUAGE OverloadedStrings #-}* *{-# LANGUAGE BangPatterns #-}* *import Control.Exception* *import Formatting* *import Formatting.Clock* *import System.Clock* *import Control.DeepSeq* *mergesort [] = []* *mergesort [x] = [x]* *mergesort xs = let (lhalf, rhalf) = splitAt (length xs `div` 2) xs* * in merge' (mergesort lhalf) (mergesort rhalf)* *merge' lhalf rhalf = merge lhalf rhalf []* *merge [] [] acc = reverse acc* *merge [] y acc = reverse acc ++ y* *merge x [] acc = reverse acc ++ x* *merge (l:ls) (r:rs) acc* * | l < r = merge ls (r:rs) (l:acc)* * | otherwise = merge rs (l:ls) (r:acc)* *toList :: String -> [Integer]* *toList input = read ("[" ++ input ++ "]")* *main = do* * file <- getLine* * contents <- readFile file* * let !unsortedlist = (toList contents)* * start <- getTime Monotonic* * evaluate(force (mergesort unsortedlist))* * end <- getTime Monotonic* * fprint (timeSpecs % "\n") start end* What am I doing wrong? -------------- next part -------------- An HTML attachment was scrubbed... URL: From kc1956 at gmail.com Fri Jul 6 02:06:10 2018 From: kc1956 at gmail.com (KC) Date: Thu, 5 Jul 2018 19:06:10 -0700 Subject: [Haskell-beginners] Execution time of Mergesort In-Reply-To: References: Message-ID: I haven't looked at the code much yet But might want to consider strictness 😎 -- Sent from an expensive device which will be obsolete in a few months Casey On Thu, Jul 5, 2018, 7:01 PM Awsaf Rahman, wrote: > Hello everyone! > > I am trying to find out the execution time of mergesort for a list size of > 1 million integers. I have done the same in Erlang as well and the > execution time in Erlang was around 0.93 seconds. I have implemented the > program in almost the same way in Haskell as well but for some reason the > Haskell implementation is taking around 12 seconds which doesn't seem > right. > > Here is the implementation in Haskell: > > *{-# LANGUAGE OverloadedStrings #-}* > *{-# LANGUAGE BangPatterns #-}* > *import Control.Exception* > *import Formatting* > *import Formatting.Clock* > *import System.Clock* > *import Control.DeepSeq* > > *mergesort [] = []* > *mergesort [x] = [x]* > *mergesort xs = let (lhalf, rhalf) = splitAt (length xs `div` 2) xs* > * in merge' (mergesort lhalf) (mergesort rhalf)* > > *merge' lhalf rhalf = merge lhalf rhalf []* > > *merge [] [] acc = reverse acc* > *merge [] y acc = reverse acc ++ y* > *merge x [] acc = reverse acc ++ x* > > *merge (l:ls) (r:rs) acc* > * | l < r = merge ls (r:rs) (l:acc)* > * | otherwise = merge rs (l:ls) (r:acc)* > > *toList :: String -> [Integer]* > *toList input = read ("[" ++ input ++ "]")* > > *main = do* > * file <- getLine* > * contents <- readFile file* > * let !unsortedlist = (toList contents)* > * start <- getTime Monotonic* > * evaluate(force (mergesort unsortedlist))* > * end <- getTime Monotonic* > * fprint (timeSpecs % "\n") start end* > > > What am I doing wrong? > _______________________________________________ > 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 awsafrahman1704 at gmail.com Fri Jul 6 02:14:37 2018 From: awsafrahman1704 at gmail.com (Awsaf Rahman) Date: Fri, 6 Jul 2018 04:14:37 +0200 Subject: [Haskell-beginners] Execution time of Mergesort In-Reply-To: References: Message-ID: I did consider strictness and that is why the execution time has come down from 16 seconds to 12 seconds! But I can't seem to find the issue anymore! On Fri, Jul 6, 2018 at 4:06 AM, KC wrote: > I haven't looked at the code much yet > But might want to consider strictness 😎 > > -- > Sent from an expensive device which will be obsolete in a few months > Casey > > On Thu, Jul 5, 2018, 7:01 PM Awsaf Rahman, > wrote: > >> Hello everyone! >> >> I am trying to find out the execution time of mergesort for a list size >> of 1 million integers. I have done the same in Erlang as well and the >> execution time in Erlang was around 0.93 seconds. I have implemented the >> program in almost the same way in Haskell as well but for some reason the >> Haskell implementation is taking around 12 seconds which doesn't seem >> right. >> >> Here is the implementation in Haskell: >> >> *{-# LANGUAGE OverloadedStrings #-}* >> *{-# LANGUAGE BangPatterns #-}* >> *import Control.Exception* >> *import Formatting* >> *import Formatting.Clock* >> *import System.Clock* >> *import Control.DeepSeq* >> >> *mergesort [] = []* >> *mergesort [x] = [x]* >> *mergesort xs = let (lhalf, rhalf) = splitAt (length xs `div` 2) xs* >> * in merge' (mergesort lhalf) (mergesort rhalf)* >> >> *merge' lhalf rhalf = merge lhalf rhalf []* >> >> *merge [] [] acc = reverse acc* >> *merge [] y acc = reverse acc ++ y* >> *merge x [] acc = reverse acc ++ x* >> >> *merge (l:ls) (r:rs) acc* >> * | l < r = merge ls (r:rs) (l:acc)* >> * | otherwise = merge rs (l:ls) (r:acc)* >> >> *toList :: String -> [Integer]* >> *toList input = read ("[" ++ input ++ "]")* >> >> *main = do* >> * file <- getLine* >> * contents <- readFile file* >> * let !unsortedlist = (toList contents)* >> * start <- getTime Monotonic* >> * evaluate(force (mergesort unsortedlist))* >> * end <- getTime Monotonic* >> * fprint (timeSpecs % "\n") start end* >> >> >> What am I doing wrong? >> _______________________________________________ >> 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 kc1956 at gmail.com Fri Jul 6 03:29:16 2018 From: kc1956 at gmail.com (KC) Date: Thu, 5 Jul 2018 20:29:16 -0700 Subject: [Haskell-beginners] Execution time of Mergesort In-Reply-To: References: Message-ID: Appending to lists is slow -- Sent from an expensive device which will be obsolete in a few months Casey On Thu, Jul 5, 2018, 7:14 PM Awsaf Rahman, wrote: > I did consider strictness and that is why the execution time has come down > from 16 seconds to 12 seconds! But I can't seem to find the issue anymore! > > On Fri, Jul 6, 2018 at 4:06 AM, KC wrote: > >> I haven't looked at the code much yet >> But might want to consider strictness 😎 >> >> -- >> Sent from an expensive device which will be obsolete in a few months >> Casey >> >> On Thu, Jul 5, 2018, 7:01 PM Awsaf Rahman, >> wrote: >> >>> Hello everyone! >>> >>> I am trying to find out the execution time of mergesort for a list size >>> of 1 million integers. I have done the same in Erlang as well and the >>> execution time in Erlang was around 0.93 seconds. I have implemented the >>> program in almost the same way in Haskell as well but for some reason the >>> Haskell implementation is taking around 12 seconds which doesn't seem >>> right. >>> >>> Here is the implementation in Haskell: >>> >>> *{-# LANGUAGE OverloadedStrings #-}* >>> *{-# LANGUAGE BangPatterns #-}* >>> *import Control.Exception* >>> *import Formatting* >>> *import Formatting.Clock* >>> *import System.Clock* >>> *import Control.DeepSeq* >>> >>> *mergesort [] = []* >>> *mergesort [x] = [x]* >>> *mergesort xs = let (lhalf, rhalf) = splitAt (length xs `div` 2) xs* >>> * in merge' (mergesort lhalf) (mergesort rhalf)* >>> >>> *merge' lhalf rhalf = merge lhalf rhalf []* >>> >>> *merge [] [] acc = reverse acc* >>> *merge [] y acc = reverse acc ++ y* >>> *merge x [] acc = reverse acc ++ x* >>> >>> *merge (l:ls) (r:rs) acc* >>> * | l < r = merge ls (r:rs) (l:acc)* >>> * | otherwise = merge rs (l:ls) (r:acc)* >>> >>> *toList :: String -> [Integer]* >>> *toList input = read ("[" ++ input ++ "]")* >>> >>> *main = do* >>> * file <- getLine* >>> * contents <- readFile file* >>> * let !unsortedlist = (toList contents)* >>> * start <- getTime Monotonic* >>> * evaluate(force (mergesort unsortedlist))* >>> * end <- getTime Monotonic* >>> * fprint (timeSpecs % "\n") start end* >>> >>> >>> What am I doing wrong? >>> _______________________________________________ >>> 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 revollat at gmail.com Fri Jul 6 07:33:32 2018 From: revollat at gmail.com (Olivier Revollat) Date: Fri, 6 Jul 2018 09:33:32 +0200 Subject: [Haskell-beginners] Passing a file containing a list as an input In-Reply-To: References: Message-ID: Hi, Maybe you should try "interact" main = io (map processIt) io f = interact (unlines . f . lines) Le jeu. 5 juil. 2018 à 22:21, Awsaf Rahman a écrit : > Hello everyone! > > I am really struggling with Haskell I/O. > > I have written a mergesort program and as an input to that program I want > to use a file containing a list of 1000 integers. Let's say the contents of > the file look like this > > [120, 400, 500 , 20, 100 ..] > > How can I achieve that? I am trying to write a main function that takes > the file as an input and passes the list to my mergesort function.. > > Regards > Awsaf Rahman > _______________________________________________ > 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 revollat at gmail.com Fri Jul 6 07:35:47 2018 From: revollat at gmail.com (Olivier Revollat) Date: Fri, 6 Jul 2018 09:35:47 +0200 Subject: [Haskell-beginners] Passing a file containing a list as an input In-Reply-To: References: Message-ID: See also http://book.realworldhaskell.org/read/io.html Example (take stdin and stdout the uppercased) import Data.Char(toUpper) main = interact (map toUpper) Le ven. 6 juil. 2018 à 09:33, Olivier Revollat a écrit : > Hi, > Maybe you should try "interact" > > main = io (map processIt) > io f = interact (unlines . f . lines) > > > > Le jeu. 5 juil. 2018 à 22:21, Awsaf Rahman a > écrit : > >> Hello everyone! >> >> I am really struggling with Haskell I/O. >> >> I have written a mergesort program and as an input to that program I want >> to use a file containing a list of 1000 integers. Let's say the contents of >> the file look like this >> >> [120, 400, 500 , 20, 100 ..] >> >> How can I achieve that? I am trying to write a main function that takes >> the file as an input and passes the list to my mergesort function.. >> >> Regards >> Awsaf Rahman >> _______________________________________________ >> 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 revollat at gmail.com Mon Jul 9 11:31:07 2018 From: revollat at gmail.com (Olivier Revollat) Date: Mon, 9 Jul 2018 13:31:07 +0200 Subject: [Haskell-beginners] How does forever works ? Message-ID: >From what I understand, this code main = forever $ do putStrLn "OK !" is equivalent to this one : main = do putStrLn "OK !" main In the second case, it's a simple recursion, so far so good ... but when I look at the implementation of "forever" i can't wrap my head around : http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Monad.html#forever forever a = let a' = a *> a' in a' How does this works ? How does this make an infinite loop ? I understand that *> discard his right argument but it doesn't help me understand how forever implement an infinite loop ... -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Mon Jul 9 11:54:29 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Mon, 9 Jul 2018 13:54:29 +0200 Subject: [Haskell-beginners] How does forever works ? In-Reply-To: References: Message-ID: <20180709115429.q3qyb7g3prgrvhqr@x60s.casa> Hello Olivier, On Mon, Jul 09, 2018 at 01:31:07PM +0200, Olivier Revollat wrote: > In the second case, it's a simple recursion, so far so good ... but when I > look at the implementation of "forever" i can't wrap my head around : > > http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Monad.html#forever forever a = let a' = a *> a' in a' `*>` is the same as `>>` (if you have ever met `>>`), with the difference that the latter works on monads only. In do notation, we could write forever :: Monad m => m a -> m b forever a = let a' = do a a' in do a' Which should be easier to get: we `do` a'; a' is nothing but a and a', so we do a and then a', which is nothing but a and a', etc. Does this explanation feel right? As soon as you can, familiarise yourself what the do notation desugars to: in my opinion plain operators are clearer -F From revollat at gmail.com Mon Jul 9 11:58:56 2018 From: revollat at gmail.com (Olivier Revollat) Date: Mon, 9 Jul 2018 13:58:56 +0200 Subject: [Haskell-beginners] How does forever works ? In-Reply-To: <20180709115429.q3qyb7g3prgrvhqr@x60s.casa> References: <20180709115429.q3qyb7g3prgrvhqr@x60s.casa> Message-ID: Hey I think it's a bit clearer now .... need to meditate on this :) Thanks ! Le lun. 9 juil. 2018 à 13:55, Francesco Ariis a écrit : > Hello Olivier, > > On Mon, Jul 09, 2018 at 01:31:07PM +0200, Olivier Revollat wrote: > > In the second case, it's a simple recursion, so far so good ... but when > I > > look at the implementation of "forever" i can't wrap my head around : > > > > > http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Monad.html#forever > > forever a = let a' = a *> a' in a' > > `*>` is the same as `>>` (if you have ever met `>>`), with the difference > that the latter works on monads only. In do notation, we could write > > forever :: Monad m => m a -> m b > forever a = let a' = do a > a' in > do a' > > Which should be easier to get: we `do` a'; a' is nothing but a and a', > so we do a and then a', which is nothing but a and a', etc. > > Does this explanation feel right? > > As soon as you can, familiarise yourself what the do notation desugars to: > in my opinion plain operators are clearer > -F > _______________________________________________ > 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 awsafrahman1704 at gmail.com Mon Jul 9 12:30:04 2018 From: awsafrahman1704 at gmail.com (Awsaf Rahman) Date: Mon, 9 Jul 2018 14:30:04 +0200 Subject: [Haskell-beginners] Storing the time difference between two Monotonic time results Message-ID: Hello, I am trying to time a function I have written in haskell using the clock package in the following way: *start <- getTime Monotonic* *evaluate(something)* *end <- getTime Monotonic* *fprint (timeSpecs % "\n") start end* Now what I want is to store the time difference between *start* and *end. *Is there a way I can do that? Regards Awsaf -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Mon Jul 9 12:45:27 2018 From: toad3k at gmail.com (David McBride) Date: Mon, 9 Jul 2018 08:45:27 -0400 Subject: [Haskell-beginners] Storing the time difference between two Monotonic time results In-Reply-To: References: Message-ID: There is a diffTimeSpec function in that module that seems like it would work. On Mon, Jul 9, 2018 at 8:30 AM, Awsaf Rahman wrote: > Hello, > > I am trying to time a function I have written in haskell using the clock > package in the following way: > > *start <- getTime Monotonic* > *evaluate(something)* > *end <- getTime Monotonic* > *fprint (timeSpecs % "\n") start end* > > > Now what I want is to store the time difference between *start* and *end. > *Is there a way I can do that? > > Regards > Awsaf > > _______________________________________________ > 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 awsafrahman1704 at gmail.com Mon Jul 9 13:08:42 2018 From: awsafrahman1704 at gmail.com (Awsaf Rahman) Date: Mon, 9 Jul 2018 15:08:42 +0200 Subject: [Haskell-beginners] Storing the time difference between two Monotonic time results In-Reply-To: References: Message-ID: I imported the System.Clock module and tried to use the diffTimeSpec function but it keeps saying "out of scope". On Mon, Jul 9, 2018 at 2:45 PM, David McBride wrote: > There is a diffTimeSpec function in that module that seems like it would > work. > > On Mon, Jul 9, 2018 at 8:30 AM, Awsaf Rahman > wrote: > >> Hello, >> >> I am trying to time a function I have written in haskell using the clock >> package in the following way: >> >> *start <- getTime Monotonic* >> *evaluate(something)* >> *end <- getTime Monotonic* >> *fprint (timeSpecs % "\n") start end* >> >> >> Now what I want is to store the time difference between *start* and *end. >> *Is there a way I can do that? >> >> Regards >> Awsaf >> >> _______________________________________________ >> 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 Mon Jul 9 13:21:05 2018 From: toad3k at gmail.com (David McBride) Date: Mon, 9 Jul 2018 09:21:05 -0400 Subject: [Haskell-beginners] Storing the time difference between two Monotonic time results In-Reply-To: References: Message-ID: I guess whatever version you are using did not export that function. In any case the definition for that function is incredibly simple, so you could just write your own for now. diffTimeSpec :: TimeSpec -> TimeSpec -> TimeSpecdiffTimeSpec ts1 ts2 = abs (ts1 - ts2) On Mon, Jul 9, 2018 at 9:08 AM, Awsaf Rahman wrote: > I imported the System.Clock module and tried to use the diffTimeSpec > function but it keeps saying "out of scope". > > On Mon, Jul 9, 2018 at 2:45 PM, David McBride wrote: > >> There is a diffTimeSpec function in that module that seems like it would >> work. >> >> On Mon, Jul 9, 2018 at 8:30 AM, Awsaf Rahman >> wrote: >> >>> Hello, >>> >>> I am trying to time a function I have written in haskell using the clock >>> package in the following way: >>> >>> *start <- getTime Monotonic* >>> *evaluate(something)* >>> *end <- getTime Monotonic* >>> *fprint (timeSpecs % "\n") start end* >>> >>> >>> Now what I want is to store the time difference between *start* and *end. >>> *Is there a way I can do that? >>> >>> Regards >>> Awsaf >>> >>> _______________________________________________ >>> 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 awsafrahman1704 at gmail.com Mon Jul 9 13:40:44 2018 From: awsafrahman1704 at gmail.com (Awsaf Rahman) Date: Mon, 9 Jul 2018 15:40:44 +0200 Subject: [Haskell-beginners] Storing the time difference between two Monotonic time results In-Reply-To: References: Message-ID: Okay, here is what I am trying to do. I am trying to time this mergesort program. I want to run this program 100, 1000, etc times and store the timing results in a list if possible. Can't seem to figure out how to do it! The following program prints the timings to the shell and I need to figure out a way to store the timings in a list. {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE BangPatterns #-} import Control.Exception import Formatting import Formatting.Clock import System.Clock import Control.DeepSeq mergesort [] = [] mergesort [x] = [x] mergesort xs = let (lhalf, rhalf) = splitAt (length xs `div` 2) xs in merge' (mergesort lhalf) (mergesort rhalf) merge' lhalf rhalf = merge lhalf rhalf [] merge [] [] acc = reverse acc merge [] y acc = reverse acc ++ y merge x [] acc = reverse acc ++ x merge (l:ls) (r:rs) acc | l < r = merge ls (r:rs) (l:acc) | otherwise = merge rs (l:ls) (r:acc) toList :: String -> [Integer] toList input = read ("[" ++ input ++ "]") repeater unsortedlist 0 result = return (result) repeater unsortedlist counter result = do start <- getTime Monotonic evaluate(mergesort unsortedlist) end <- getTime Monotonic fprint (timeSpecs % "\n") start end repeater unsortedlist (counter-1) result main = do file <- getLine contents <- readFile file let !unsortedlist = (toList contents) repeater unsortedlist 100 [] On Mon, Jul 9, 2018 at 3:21 PM, David McBride wrote: > I guess whatever version you are using did not export that function. In > any case the definition for that function is incredibly simple, so you > could just write your own for now. > > diffTimeSpec :: TimeSpec -> TimeSpec -> TimeSpecdiffTimeSpec ts1 ts2 = abs (ts1 - ts2) > > > > On Mon, Jul 9, 2018 at 9:08 AM, Awsaf Rahman > wrote: > >> I imported the System.Clock module and tried to use the diffTimeSpec >> function but it keeps saying "out of scope". >> >> On Mon, Jul 9, 2018 at 2:45 PM, David McBride wrote: >> >>> There is a diffTimeSpec function in that module that seems like it >>> would work. >>> >>> On Mon, Jul 9, 2018 at 8:30 AM, Awsaf Rahman >>> wrote: >>> >>>> Hello, >>>> >>>> I am trying to time a function I have written in haskell using the >>>> clock package in the following way: >>>> >>>> *start <- getTime Monotonic* >>>> *evaluate(something)* >>>> *end <- getTime Monotonic* >>>> *fprint (timeSpecs % "\n") start end* >>>> >>>> >>>> Now what I want is to store the time difference between *start* and *end. >>>> *Is there a way I can do that? >>>> >>>> Regards >>>> Awsaf >>>> >>>> _______________________________________________ >>>> 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 >> >> > > _______________________________________________ > 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 Mon Jul 9 19:29:46 2018 From: jeffbrown.the at gmail.com (Jeffrey Brown) Date: Mon, 9 Jul 2018 14:29:46 -0500 Subject: [Haskell-beginners] Where to report an unfriendly feature (if not a bug) in `stack ghci`? In-Reply-To: References: Message-ID: Strange -- that page indicates the suggestion was applied, but when I try it, it doesn't work: Configuring GHCi with the following packages: GHCi, version 8.2.2: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /tmp/ghci10227/ghci-script Prelude> :set prompt "> " > :{ Prelude| 3 Prelude| :} 3 > :set prompt2 "> " Some flags have not been recognized: prompt2, > > :{ Prelude| 3 Prelude| :} 3 > On Wed, Jul 4, 2018 at 7:31 AM Ut Primum wrote: > Hi, > I think the same was reported here: > > https://ghc.haskell.org/trac/ghc/ticket/7509#no1 > > Ut > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Jeff Brown | Jeffrey Benjamin Brown Website | Facebook | LinkedIn (spammy, so I often miss messages here) | Github -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Mon Jul 9 19:52:00 2018 From: toad3k at gmail.com (David McBride) Date: Mon, 9 Jul 2018 15:52:00 -0400 Subject: [Haskell-beginners] Storing the time difference between two Monotonic time results In-Reply-To: References: Message-ID: toList :: String -> [Integer] toList input = read ("[" ++ input ++ "]") That was creative, but a more idiomatic way to write that would be to use the split package stack ghci --package split import Data.Split toList :: String -> [Integer] toList = fmap read . splitOn "," As for how to aggregate times, start thinking about the types before you start. Each iteration you should take a List and return a TimeSpec. testcase :: [Integer] -> IO TimeSpec testcase l = do start <- getTime Monotonic evaluate (mergesort l) end <- getTime Monotonic return $ diffTimeSpec start end Now, we need to run it 100 times and collect the times. Sounds like a job for map, but since testcase is monadic, use mapM instead (or traverse). main = do unsortedList <- undefined times <- mapM (\c -> testcase unsortedList) [1..100] print times On Mon, Jul 9, 2018 at 9:40 AM, Awsaf Rahman wrote: > Okay, here is what I am trying to do. I am trying to time this mergesort > program. I want to run this program 100, 1000, etc times and store the > timing results in a list if possible. Can't seem to figure out how to do > it! The following program prints the timings to the shell and I need to > figure out a way to store the timings in a list. > > > {-# LANGUAGE OverloadedStrings #-} > {-# LANGUAGE BangPatterns #-} > import Control.Exception > import Formatting > import Formatting.Clock > import System.Clock > import Control.DeepSeq > > mergesort [] = [] > mergesort [x] = [x] > mergesort xs = let (lhalf, rhalf) = splitAt (length xs `div` 2) xs > in merge' (mergesort lhalf) (mergesort rhalf) > > merge' lhalf rhalf = merge lhalf rhalf [] > > merge [] [] acc = reverse acc > merge [] y acc = reverse acc ++ y > merge x [] acc = reverse acc ++ x > > merge (l:ls) (r:rs) acc > | l < r = merge ls (r:rs) (l:acc) > | otherwise = merge rs (l:ls) (r:acc) > > toList :: String -> [Integer] > toList input = read ("[" ++ input ++ "]") > > repeater unsortedlist 0 result = return (result) > > repeater unsortedlist counter result = do > start <- getTime Monotonic > evaluate(mergesort unsortedlist) > end <- getTime Monotonic > fprint (timeSpecs % "\n") start end > repeater unsortedlist (counter-1) result > > main = do > file <- getLine > contents <- readFile file > let !unsortedlist = (toList contents) > repeater unsortedlist 100 [] > > > On Mon, Jul 9, 2018 at 3:21 PM, David McBride wrote: > >> I guess whatever version you are using did not export that function. In >> any case the definition for that function is incredibly simple, so you >> could just write your own for now. >> >> diffTimeSpec :: TimeSpec -> TimeSpec -> TimeSpecdiffTimeSpec ts1 ts2 = abs (ts1 - ts2) >> >> >> >> On Mon, Jul 9, 2018 at 9:08 AM, Awsaf Rahman >> wrote: >> >>> I imported the System.Clock module and tried to use the diffTimeSpec >>> function but it keeps saying "out of scope". >>> >>> On Mon, Jul 9, 2018 at 2:45 PM, David McBride wrote: >>> >>>> There is a diffTimeSpec function in that module that seems like it >>>> would work. >>>> >>>> On Mon, Jul 9, 2018 at 8:30 AM, Awsaf Rahman >>> > wrote: >>>> >>>>> Hello, >>>>> >>>>> I am trying to time a function I have written in haskell using the >>>>> clock package in the following way: >>>>> >>>>> *start <- getTime Monotonic* >>>>> *evaluate(something)* >>>>> *end <- getTime Monotonic* >>>>> *fprint (timeSpecs % "\n") start end* >>>>> >>>>> >>>>> Now what I want is to store the time difference between *start* and *end. >>>>> *Is there a way I can do that? >>>>> >>>>> Regards >>>>> Awsaf >>>>> >>>>> _______________________________________________ >>>>> 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 >>> >>> >> >> _______________________________________________ >> 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 revollat at gmail.com Tue Jul 10 09:22:17 2018 From: revollat at gmail.com (Olivier Revollat) Date: Tue, 10 Jul 2018 11:22:17 +0200 Subject: [Haskell-beginners] Haskell for Imperative Programmers Message-ID: Hi, I've been using imperative languages for 20 years now :) I'm a beginner in haskell and I love the paradigm shift you feel when you come from imperative programming. I found interesting articles like : https://wiki.haskell.org/Haskell_IO_for_Imperative_Programmers Do you have any other ressources like that ? I'm not looking for how to use haskell in imperative style (e.g. with "do" notation, ...) no no ! I'm looking articles who explain how NOT TO USE imperative style with haskell, and help thinking the paradigm shift ... Thanks :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From aquagnu at gmail.com Tue Jul 10 11:13:52 2018 From: aquagnu at gmail.com (PY) Date: Tue, 10 Jul 2018 14:13:52 +0300 Subject: [Haskell-beginners] Haskell for Imperative Programmers In-Reply-To: References: Message-ID: <9a793b1f-69a9-0116-a1be-ec3096343d96@gmail.com> May be something like this? *Free monads* ("applicative" style/interpreting trees) and Effects: https://markkarpov.com/post/free-monad-considered-harmful.html https://mmhaskell.com/blog/2017/11/20/eff-to-the-rescue *Arrows* (something like "flow"-style): https://www.haskell.org/arrows/ http://tuttlem.github.io/2014/07/26/practical-arrow-usage.html 10.07.2018 12:22, Olivier Revollat wrote: > Hi, > I've been using imperative languages for 20 years now :) > > I'm a beginner in haskell and I love the paradigm shift you feel when > you come from imperative programming. I found interesting articles like : > https://wiki.haskell.org/Haskell_IO_for_Imperative_Programmers > > Do you have any other ressources like that ? > I'm not looking for how to use haskell in imperative style (e.g. with > "do" notation, ...) no no ! I'm looking articles who explain how NOT > TO USE imperative style with haskell, and help thinking the paradigm > shift ... > > 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 revollat at gmail.com Tue Jul 10 11:55:06 2018 From: revollat at gmail.com (Olivier Revollat) Date: Tue, 10 Jul 2018 13:55:06 +0200 Subject: [Haskell-beginners] Haskell for Imperative Programmers In-Reply-To: <9a793b1f-69a9-0116-a1be-ec3096343d96@gmail.com> References: <9a793b1f-69a9-0116-a1be-ec3096343d96@gmail.com> Message-ID: Thanks ! Le mar. 10 juil. 2018 à 13:14, PY a écrit : > May be something like this? > > *Free monads* ("applicative" style/interpreting trees) and Effects: > https://markkarpov.com/post/free-monad-considered-harmful.html > https://mmhaskell.com/blog/2017/11/20/eff-to-the-rescue > > *Arrows* (something like "flow"-style): > https://www.haskell.org/arrows/ > http://tuttlem.github.io/2014/07/26/practical-arrow-usage.html > > > 10.07.2018 12:22, Olivier Revollat wrote: > > Hi, > I've been using imperative languages for 20 years now :) > > I'm a beginner in haskell and I love the paradigm shift you feel when you > come from imperative programming. I found interesting articles like : > https://wiki.haskell.org/Haskell_IO_for_Imperative_Programmers > > Do you have any other ressources like that ? > I'm not looking for how to use haskell in imperative style (e.g. with "do" > notation, ...) no no ! I'm looking articles who explain how NOT TO USE > imperative style with haskell, and help thinking the paradigm shift ... > > Thanks :) > > > > _______________________________________________ > Beginners mailing listBeginners at haskell.orghttp://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 tanuki at gmail.com Tue Jul 10 12:19:41 2018 From: tanuki at gmail.com (Theodore Lief Gannon) Date: Tue, 10 Jul 2018 05:19:41 -0700 Subject: [Haskell-beginners] Haskell for Imperative Programmers In-Reply-To: References: <9a793b1f-69a9-0116-a1be-ec3096343d96@gmail.com> Message-ID: An intuition that really clicked for me is that in Haskell IO code, as in all Haskell code, you are describing a pristine and perfectly inert data structure. It happens to *represent* a set of imperative instructions that the totally impure runtime environment can execute, but that's not your problem! On Tue, Jul 10, 2018, 4:55 AM Olivier Revollat wrote: > Thanks ! > > Le mar. 10 juil. 2018 à 13:14, PY a écrit : > >> May be something like this? >> >> *Free monads* ("applicative" style/interpreting trees) and Effects: >> https://markkarpov.com/post/free-monad-considered-harmful.html >> https://mmhaskell.com/blog/2017/11/20/eff-to-the-rescue >> >> *Arrows* (something like "flow"-style): >> https://www.haskell.org/arrows/ >> http://tuttlem.github.io/2014/07/26/practical-arrow-usage.html >> >> >> 10.07.2018 12:22, Olivier Revollat wrote: >> >> Hi, >> I've been using imperative languages for 20 years now :) >> >> I'm a beginner in haskell and I love the paradigm shift you feel when you >> come from imperative programming. I found interesting articles like : >> https://wiki.haskell.org/Haskell_IO_for_Imperative_Programmers >> >> Do you have any other ressources like that ? >> I'm not looking for how to use haskell in imperative style (e.g. with >> "do" notation, ...) no no ! I'm looking articles who explain how NOT TO USE >> imperative style with haskell, and help thinking the paradigm shift ... >> >> Thanks :) >> >> >> >> _______________________________________________ >> Beginners mailing listBeginners at haskell.orghttp://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 revollat at gmail.com Tue Jul 10 12:29:41 2018 From: revollat at gmail.com (Olivier Revollat) Date: Tue, 10 Jul 2018 14:29:41 +0200 Subject: [Haskell-beginners] Haskell for Imperative Programmers In-Reply-To: References: <9a793b1f-69a9-0116-a1be-ec3096343d96@gmail.com> Message-ID: Yes absolutely ! you're referring to laziness right ? Le mar. 10 juil. 2018 à 14:20, Theodore Lief Gannon a écrit : > An intuition that really clicked for me is that in Haskell IO code, as in > all Haskell code, you are describing a pristine and perfectly inert data > structure. It happens to *represent* a set of imperative instructions that > the totally impure runtime environment can execute, but that's not your > problem! > > On Tue, Jul 10, 2018, 4:55 AM Olivier Revollat wrote: > >> Thanks ! >> >> Le mar. 10 juil. 2018 à 13:14, PY a écrit : >> >>> May be something like this? >>> >>> *Free monads* ("applicative" style/interpreting trees) and Effects: >>> https://markkarpov.com/post/free-monad-considered-harmful.html >>> https://mmhaskell.com/blog/2017/11/20/eff-to-the-rescue >>> >>> *Arrows* (something like "flow"-style): >>> https://www.haskell.org/arrows/ >>> http://tuttlem.github.io/2014/07/26/practical-arrow-usage.html >>> >>> >>> 10.07.2018 12:22, Olivier Revollat wrote: >>> >>> Hi, >>> I've been using imperative languages for 20 years now :) >>> >>> I'm a beginner in haskell and I love the paradigm shift you feel when >>> you come from imperative programming. I found interesting articles like : >>> https://wiki.haskell.org/Haskell_IO_for_Imperative_Programmers >>> >>> Do you have any other ressources like that ? >>> I'm not looking for how to use haskell in imperative style (e.g. with >>> "do" notation, ...) no no ! I'm looking articles who explain how NOT TO USE >>> imperative style with haskell, and help thinking the paradigm shift ... >>> >>> Thanks :) >>> >>> >>> >>> _______________________________________________ >>> Beginners mailing listBeginners at haskell.orghttp://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 >> > _______________________________________________ > 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 ionut.g.stan at gmail.com Tue Jul 10 12:34:30 2018 From: ionut.g.stan at gmail.com (=?UTF-8?Q?Ionu=c8=9b_G._Stan?=) Date: Tue, 10 Jul 2018 15:34:30 +0300 Subject: [Haskell-beginners] Haskell for Imperative Programmers In-Reply-To: References: <9a793b1f-69a9-0116-a1be-ec3096343d96@gmail.com> Message-ID: On 10/07/2018 15:19, Theodore Lief Gannon wrote: > An intuition that really clicked for me is that in Haskell IO code, as > in all Haskell code, you are describing a pristine and perfectly inert > data structure. It happens to *represent* a set of imperative > instructions that the totally impure runtime environment can execute, > but that's not your problem! Just like in Java :) I'm kinda trolling a bit, but if I spend all my dev time inside an IO monad of sorts, I don't find that to be much different than writing Java. > On Tue, Jul 10, 2018, 4:55 AM Olivier Revollat > wrote: > > Thanks ! > > Le mar. 10 juil. 2018 à 13:14, PY > a écrit : > > May be something like this? > > *Free monads* ("applicative" style/interpreting trees) and Effects: > > https://markkarpov.com/post/free-monad-considered-harmful.html > https://mmhaskell.com/blog/2017/11/20/eff-to-the-rescue > > *Arrows* (something like "flow"-style): > https://www.haskell.org/arrows/ > http://tuttlem.github.io/2014/07/26/practical-arrow-usage.html > > > 10.07.2018 12:22, Olivier Revollat wrote: >> Hi, >> I've been using imperative languages for 20 years now :) >> >> I'm a beginner in haskell and I love the paradigm shift you >> feel when you come from imperative programming. I found >> interesting articles like : >> https://wiki.haskell.org/Haskell_IO_for_Imperative_Programmers >> >> Do you have any other ressources like that ? >> I'm not looking for how to use haskell in imperative style >> (e.g. with "do" notation, ...) no no ! I'm looking articles >> who explain how NOT TO USE imperative style with haskell, and >> help thinking the paradigm shift ... >> >> Thanks :) >> >> >> >> _______________________________________________ >> 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 > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Ionuț G. Stan | http://igstan.ro | http://bucharestfp.ro From toad3k at gmail.com Tue Jul 10 12:50:42 2018 From: toad3k at gmail.com (David McBride) Date: Tue, 10 Jul 2018 08:50:42 -0400 Subject: [Haskell-beginners] Haskell for Imperative Programmers In-Reply-To: References: <9a793b1f-69a9-0116-a1be-ec3096343d96@gmail.com> Message-ID: No, he means that an IO action is just another type. For example you can have a list of IO actions, Then you can take one of them and execute them. Then you can execute that one action again as many times as you want, because an IO action is just a type like any other type until it is executed. These examples are utterly contrived. foo :: [IO String] foo = [return "25", print "hello" >> return "qwerty", getLine] foo !! 3 :: IO String bar :: [IO Int] bar = map (fmap read) foo main :: IO () main = do str <- foo !! 2 print str str2 <- foo !! 2 print str2 i <- head bar print (i + 1) Even main is just a data structure until the compiler decides to execute it. It could have been written as an expression. main = foo !! 2 >>= \str -> print str >> foo !! 2 >>= \str2 -> print str2 >> head bar >>= \i -> print (i + 1) On Tue, Jul 10, 2018 at 8:29 AM, Olivier Revollat wrote: > Yes absolutely ! you're referring to laziness right ? > > > Le mar. 10 juil. 2018 à 14:20, Theodore Lief Gannon a > écrit : > >> An intuition that really clicked for me is that in Haskell IO code, as in >> all Haskell code, you are describing a pristine and perfectly inert data >> structure. It happens to *represent* a set of imperative instructions that >> the totally impure runtime environment can execute, but that's not your >> problem! >> >> On Tue, Jul 10, 2018, 4:55 AM Olivier Revollat >> wrote: >> >>> Thanks ! >>> >>> Le mar. 10 juil. 2018 à 13:14, PY a écrit : >>> >>>> May be something like this? >>>> >>>> *Free monads* ("applicative" style/interpreting trees) and Effects: >>>> https://markkarpov.com/post/free-monad-considered-harmful.html >>>> https://mmhaskell.com/blog/2017/11/20/eff-to-the-rescue >>>> >>>> *Arrows* (something like "flow"-style): >>>> https://www.haskell.org/arrows/ >>>> http://tuttlem.github.io/2014/07/26/practical-arrow-usage.html >>>> >>>> >>>> 10.07.2018 12:22, Olivier Revollat wrote: >>>> >>>> Hi, >>>> I've been using imperative languages for 20 years now :) >>>> >>>> I'm a beginner in haskell and I love the paradigm shift you feel when >>>> you come from imperative programming. I found interesting articles like : >>>> https://wiki.haskell.org/Haskell_IO_for_Imperative_Programmers >>>> >>>> Do you have any other ressources like that ? >>>> I'm not looking for how to use haskell in imperative style (e.g. with >>>> "do" notation, ...) no no ! I'm looking articles who explain how NOT TO USE >>>> imperative style with haskell, and help thinking the paradigm shift ... >>>> >>>> Thanks :) >>>> >>>> >>>> >>>> _______________________________________________ >>>> Beginners mailing listBeginners at haskell.orghttp://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 >>> >> _______________________________________________ >> 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 aquagnu at gmail.com Tue Jul 10 13:05:49 2018 From: aquagnu at gmail.com (PY) Date: Tue, 10 Jul 2018 16:05:49 +0300 Subject: [Haskell-beginners] Haskell for Imperative Programmers In-Reply-To: References: <9a793b1f-69a9-0116-a1be-ec3096343d96@gmail.com> Message-ID: <3d14b011-0663-0368-f048-8170baa406a3@gmail.com> More interesting example from Gabriel Gonzalez: http://www.haskellforall.com/2018/02/the-wizard-monoid.html  :) 10.07.2018 15:50, David McBride wrote: > No, he means that an IO action is just another type.  For example you > can have a list of IO actions, Then you can take one of them and > execute them.  Then you can execute that one action again as many > times as you want, because an IO action is just a type like any other > type until it is executed. These examples are utterly contrived. > > foo :: [IO String] > foo = [return "25", print "hello" >> return "qwerty", getLine] > > foo !! 3 :: IO String > > bar :: [IO Int] > bar = map (fmap read) foo > > main :: IO () > main = do >   str <- foo !! 2 >   print str >   str2 <- foo !! 2 >   print str2 >   i <- head bar >   print (i + 1) > > Even main is just a data structure until the compiler decides to > execute it.  It could have been written as an expression. > > main = foo !! 2 >>= \str -> print str >> foo !! 2 >>= \str2 -> print > str2 >> head bar >>= \i -> print (i + 1) > > > > > > > On Tue, Jul 10, 2018 at 8:29 AM, Olivier Revollat > wrote: > > Yes absolutely ! you're referring to laziness right ? > > > Le mar. 10 juil. 2018 à 14:20, Theodore Lief Gannon > > a écrit : > > An intuition that really clicked for me is that in Haskell IO > code, as in all Haskell code, you are describing a pristine > and perfectly inert data structure. It happens to *represent* > a set of imperative instructions that the totally impure > runtime environment can execute, but that's not your problem! > > On Tue, Jul 10, 2018, 4:55 AM Olivier Revollat > > wrote: > > Thanks ! > > Le mar. 10 juil. 2018 à 13:14, PY > a écrit : > > May be something like this? > > *Free monads* ("applicative" style/interpreting trees) > and Effects: > > https://markkarpov.com/post/free-monad-considered-harmful.html > > https://mmhaskell.com/blog/2017/11/20/eff-to-the-rescue > > > *Arrows* (something like "flow"-style): > https://www.haskell.org/arrows/ > > http://tuttlem.github.io/2014/07/26/practical-arrow-usage.html > > > > 10.07.2018 12:22, Olivier Revollat wrote: >> Hi, >> I've been using imperative languages for 20 years now :) >> >> I'm a beginner in haskell and I love the paradigm >> shift you feel when you come from imperative >> programming. I found interesting articles like : >> https://wiki.haskell.org/Haskell_IO_for_Imperative_Programmers >> >> >> Do you have any other ressources like that ? >> I'm not looking for how to use haskell in imperative >> style (e.g. with "do" notation, ...) no no ! I'm >> looking articles who explain how NOT TO USE >> imperative style with haskell, and help thinking the >> paradigm shift ... >> >> Thanks :) >> >> >> >> _______________________________________________ >> 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 > > > _______________________________________________ > 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 tanuki at gmail.com Wed Jul 11 00:53:54 2018 From: tanuki at gmail.com (Theodore Lief Gannon) Date: Tue, 10 Jul 2018 17:53:54 -0700 Subject: [Haskell-beginners] Haskell for Imperative Programmers In-Reply-To: <3d14b011-0663-0368-f048-8170baa406a3@gmail.com> References: <9a793b1f-69a9-0116-a1be-ec3096343d96@gmail.com> <3d14b011-0663-0368-f048-8170baa406a3@gmail.com> Message-ID: Thank you David and PY, that is exactly what I meant. And of course, Gabriel's blog knocks it out of the park as usual! On Tue, Jul 10, 2018, 6:06 AM PY wrote: > More interesting example from Gabriel Gonzalez: > http://www.haskellforall.com/2018/02/the-wizard-monoid.html :) > > 10.07.2018 15:50, David McBride wrote: > > No, he means that an IO action is just another type. For example you can > have a list of IO actions, Then you can take one of them and execute them. > Then you can execute that one action again as many times as you want, > because an IO action is just a type like any other type until it is > executed. These examples are utterly contrived. > > foo :: [IO String] > foo = [return "25", print "hello" >> return "qwerty", getLine] > > foo !! 3 :: IO String > > bar :: [IO Int] > bar = map (fmap read) foo > > main :: IO () > main = do > str <- foo !! 2 > print str > str2 <- foo !! 2 > print str2 > i <- head bar > print (i + 1) > > Even main is just a data structure until the compiler decides to execute > it. It could have been written as an expression. > > main = foo !! 2 >>= \str -> print str >> foo !! 2 >>= \str2 -> print str2 > >> head bar >>= \i -> print (i + 1) > > > > > > > On Tue, Jul 10, 2018 at 8:29 AM, Olivier Revollat > wrote: > >> Yes absolutely ! you're referring to laziness right ? >> >> >> Le mar. 10 juil. 2018 à 14:20, Theodore Lief Gannon a >> écrit : >> >>> An intuition that really clicked for me is that in Haskell IO code, as >>> in all Haskell code, you are describing a pristine and perfectly inert data >>> structure. It happens to *represent* a set of imperative instructions that >>> the totally impure runtime environment can execute, but that's not your >>> problem! >>> >>> On Tue, Jul 10, 2018, 4:55 AM Olivier Revollat >>> wrote: >>> >>>> Thanks ! >>>> >>>> Le mar. 10 juil. 2018 à 13:14, PY a écrit : >>>> >>>>> May be something like this? >>>>> >>>>> *Free monads* ("applicative" style/interpreting trees) and Effects: >>>>> https://markkarpov.com/post/free-monad-considered-harmful.html >>>>> https://mmhaskell.com/blog/2017/11/20/eff-to-the-rescue >>>>> >>>>> *Arrows* (something like "flow"-style): >>>>> https://www.haskell.org/arrows/ >>>>> http://tuttlem.github.io/2014/07/26/practical-arrow-usage.html >>>>> >>>>> >>>>> 10.07.2018 12:22, Olivier Revollat wrote: >>>>> >>>>> Hi, >>>>> I've been using imperative languages for 20 years now :) >>>>> >>>>> I'm a beginner in haskell and I love the paradigm shift you feel when >>>>> you come from imperative programming. I found interesting articles like : >>>>> https://wiki.haskell.org/Haskell_IO_for_Imperative_Programmers >>>>> >>>>> Do you have any other ressources like that ? >>>>> I'm not looking for how to use haskell in imperative style (e.g. with >>>>> "do" notation, ...) no no ! I'm looking articles who explain how NOT TO USE >>>>> imperative style with haskell, and help thinking the paradigm shift ... >>>>> >>>>> Thanks :) >>>>> >>>>> >>>>> >>>>> _______________________________________________ >>>>> Beginners mailing listBeginners at haskell.orghttp://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 >>>> >>> _______________________________________________ >>> 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 listBeginners at haskell.orghttp://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 50295 at web.de Wed Jul 11 17:24:19 2018 From: 50295 at web.de (Olumide) Date: Wed, 11 Jul 2018 18:24:19 +0100 Subject: [Haskell-beginners] Two small questions from the section "Making a safe RPN calculator" in LYAH Message-ID: Dear List, Question 1: In the section "Making a safe RPN calculator" of LYAH (Chapter 14 -- http://learnyouahaskell.com/for-a-few-monads-more#useful-monadic-functions) there is an expression: read numberString:xs, take from the last line of the function foldingFunction :: [Double] -> String -> [Double] foldingFunction (x:y:ys) "*" = (x * y):ys foldingFunction (x:y:ys) "+" = (x + y):ys foldingFunction (x:y:ys) "-" = (y - x):ys foldingFunction xs numberString = read numberString:xs My first question is why is the read function called before the cons operator? Question 2: The same section of the book also introduces the reads function which is used to implement the readMaybe function and a refactored foldingFunction readMaybe :: (Read a) => String -> Maybe a readMaybe st = case reads st of [(x,"")] -> Just x _ -> Nothing foldingFunction :: [Double] -> String -> Maybe [Double] foldingFunction (x:y:ys) "*" = return ((x * y):ys) foldingFunction (x:y:ys) "+" = return ((x + y):ys) foldingFunction (x:y:ys) "-" = return ((y - x):ys) foldingFunction xs numberString = liftM (:xs) (readMaybe numberString) I'd like to know why the foldingFunction returns Nothing in the following example: ghci> foldingFunction [] "1 wawawawa" Nothing Considering that reads "1 wawawawa" does not return Nothing, as follows ghci> reads "1 wawawawa" :: [(Double,String)] [(1.0," wawawawa")] Regards, - Olumide From toad3k at gmail.com Wed Jul 11 17:30:51 2018 From: toad3k at gmail.com (David McBride) Date: Wed, 11 Jul 2018 13:30:51 -0400 Subject: [Haskell-beginners] Two small questions from the section "Making a safe RPN calculator" in LYAH In-Reply-To: References: Message-ID: 1) Not entirely sure what you mean. The expression is parsed as (read numberString) : xs, which means that the result number is prepended to the front of the list. 2) Because [(x,"")] does not match [(1.0," wawawawa")]. An empty string does not match a string with characters in it. On Wed, Jul 11, 2018 at 1:24 PM, Olumide <50295 at web.de> wrote: > Dear List, > > Question 1: > In the section "Making a safe RPN calculator" of LYAH (Chapter 14 -- > http://learnyouahaskell.com/for-a-few-monads-more#useful-monadic-functions) > there is an expression: read numberString:xs, take from the last line of > the function > > foldingFunction :: [Double] -> String -> [Double] > foldingFunction (x:y:ys) "*" = (x * y):ys > foldingFunction (x:y:ys) "+" = (x + y):ys > foldingFunction (x:y:ys) "-" = (y - x):ys > foldingFunction xs numberString = read numberString:xs > > My first question is why is the read function called before the cons > operator? > > Question 2: > The same section of the book also introduces the reads function which is > used to implement the readMaybe function and a refactored foldingFunction > > readMaybe :: (Read a) => String -> Maybe a > readMaybe st = case reads st of [(x,"")] -> Just x > _ -> Nothing > > foldingFunction :: [Double] -> String -> Maybe [Double] > foldingFunction (x:y:ys) "*" = return ((x * y):ys) > foldingFunction (x:y:ys) "+" = return ((x + y):ys) > foldingFunction (x:y:ys) "-" = return ((y - x):ys) > foldingFunction xs numberString = liftM (:xs) (readMaybe numberString) > > I'd like to know why the foldingFunction returns Nothing in the following > example: > > ghci> foldingFunction [] "1 wawawawa" > Nothing > > Considering that reads "1 wawawawa" does not return Nothing, as follows > > ghci> reads "1 wawawawa" :: [(Double,String)] > [(1.0," wawawawa")] > > Regards, > > - Olumide > > _______________________________________________ > 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 patrik.mrx at gmail.com Thu Jul 12 10:05:52 2018 From: patrik.mrx at gmail.com (mrx) Date: Thu, 12 Jul 2018 12:05:52 +0200 Subject: [Haskell-beginners] The type class Read Message-ID: Hi, I'm trying to make sense of the type class `Read`. It feels to be like a function performing casting to me, similar to what you have in C and Java. The weird thing is that the casting doesn't have to make sense, type-wise. So `read "5" :: Int` produce the integer 5 which make sense but `read "(3,'a')" :: Int` doesn't make sense to me but ghci accepts it! This is seeing Read as a function, as it's a type class i suspect I'm missing something. Quite possibly quite a lot... Why is the type class called `Read`? What am I missing above? // Patrik Iselind -------------- next part -------------- An HTML attachment was scrubbed... URL: From aquagnu at gmail.com Thu Jul 12 11:08:29 2018 From: aquagnu at gmail.com (PY) Date: Thu, 12 Jul 2018 14:08:29 +0300 Subject: [Haskell-beginners] The type class Read In-Reply-To: References: Message-ID: read "(3,'a')"::(Int, Char)  returns expected tuple. But with ":: Int" leads to runtime exception, because it calls `readsPrec` of Int and can not parse such string. But readsPrec of (a,b) where both are readable parses it successfully. 12.07.2018 13:05, mrx wrote: > Hi, > > I'm trying to make sense of the type class `Read`. It feels to be like > a function performing casting to me, similar to what you have in C and > Java. > > The weird thing is that the casting doesn't have to make sense, > type-wise. So `read "5" :: Int` produce the integer 5 which make sense > but `read "(3,'a')" :: Int` doesn't make sense to me but ghci accepts it! > > This is seeing Read as a function, as it's a type class i suspect I'm > missing something. Quite possibly quite a lot... > > Why is the type class called `Read`? > What am I missing above? > > // Patrik Iselind > > > _______________________________________________ > 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 Thu Jul 12 11:14:32 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Thu, 12 Jul 2018 13:14:32 +0200 Subject: [Haskell-beginners] The type class Read In-Reply-To: References: Message-ID: <20180712111432.ht3mrwj6x2gwtnh5@x60s.casa> Hello Patrik, On Thu, Jul 12, 2018 at 12:05:52PM +0200, mrx wrote: > Why is the type class called `Read`? > What am I missing above? we can say any instance of `Read` has to implement read :: Read a => String -> a -- the actual instance implements a different function, -- but that's not relevant for our example So, a typeclass (Read, capital `r`) gives us a function (`read`, lower-case `r`). The function goes from `String` (and no other things) to our implemented type. As you discovered, the conversion happens at runtime, the compiler has no way to check it beforehand, and things might explode during execution λ> read "18" :: Char *** Exception: Prelude.read: no parse λ> read "diciotto" :: Int *** Exception: Prelude.read: no parse It is often a good idea to use `readMay` (from Safe) to handle failures locally without throwing an exception readMay :: Read a => String -> Maybe a Does this answers your question? If you have any further doubts, shoot again -F From patrik.mrx at gmail.com Fri Jul 13 07:06:51 2018 From: patrik.mrx at gmail.com (mrx) Date: Fri, 13 Jul 2018 09:06:51 +0200 Subject: [Haskell-beginners] The type class Read In-Reply-To: <20180712111432.ht3mrwj6x2gwtnh5@x60s.casa> References: <20180712111432.ht3mrwj6x2gwtnh5@x60s.casa> Message-ID: Den tors 12 juli 2018 13:15Francesco Ariis skrev: > Hello Patrik, > > On Thu, Jul 12, 2018 at 12:05:52PM +0200, mrx wrote: > > Why is the type class called `Read`? > > What am I missing above? > > we can say any instance of `Read` has to implement > > read :: Read a => String -> a > -- the actual instance implements a different function, > -- but that's not relevant for our example > > So, a typeclass (Read, capital `r`) gives us a function (`read`, > lower-case `r`). The function goes from `String` (and no other > things) to our implemented type. > That makes sense to me based on the type, sure. So read is some form of casting then? Does this answers your question? Maybe, but I still don't see what I'd use it for. Is it used to for example read the contents of a file whose file name is provided as that string? // Patrik -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Fri Jul 13 07:30:37 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Fri, 13 Jul 2018 09:30:37 +0200 Subject: [Haskell-beginners] The type class Read In-Reply-To: References: <20180712111432.ht3mrwj6x2gwtnh5@x60s.casa> Message-ID: <20180713073037.4edxksgtcmb4rlav@x60s.casa> On Fri, Jul 13, 2018 at 09:06:51AM +0200, mrx wrote: > That makes sense to me based on the type, sure. So read is some form of > casting then? Yep, but just from `String` and nothing else. > > Does this answers your question? > > > Maybe, but I still don't see what I'd use it for. Is it used to for example > read the contents of a file whose file name is provided as that string? No, you would use `readFile` for that: readFile :: FilePath -> IO String -- Filepath is a type synonym for `String` You would use `read` to convert simple user input (which is usually collected as String) into, say, Integers getLine :: IO String -- this could need read And in general, `Read` is supposed to be compatible with `Show`, so if you used `show` for any reason (some form of cheap serialisation, etc.), `read` should work back the type: λ> show [1..10] "[1,2,3,4,5,6,7,8,9,10]" λ> read it :: [Int] [1,2,3,4,5,6,7,8,9,10] tl;dr: cheap type parsing. For any more specialised/complex parsing, use a proper parsing library like Parsec. From patrik.mrx at gmail.com Fri Jul 13 08:14:56 2018 From: patrik.mrx at gmail.com (mrx) Date: Fri, 13 Jul 2018 10:14:56 +0200 Subject: [Haskell-beginners] The type class Read In-Reply-To: <20180713073037.4edxksgtcmb4rlav@x60s.casa> References: <20180712111432.ht3mrwj6x2gwtnh5@x60s.casa> <20180713073037.4edxksgtcmb4rlav@x60s.casa> Message-ID: Ah, I see. Thanks a lot for the clarification! Patrik Iselind Den fre 13 juli 2018 09:31Francesco Ariis skrev: > On Fri, Jul 13, 2018 at 09:06:51AM +0200, mrx wrote: > > That makes sense to me based on the type, sure. So read is some form of > > casting then? > > Yep, but just from `String` and nothing else. > > > > > Does this answers your question? > > > > > > Maybe, but I still don't see what I'd use it for. Is it used to for > example > > read the contents of a file whose file name is provided as that string? > > No, you would use `readFile` for that: > > readFile :: FilePath -> IO String > -- Filepath is a type synonym for `String` > > You would use `read` to convert simple user input (which is usually > collected as String) into, say, Integers > > getLine :: IO String > -- this could need read > > And in general, `Read` is supposed to be compatible with `Show`, so > if you used `show` for any reason (some form of cheap serialisation, > etc.), `read` should work back the type: > > λ> show [1..10] > "[1,2,3,4,5,6,7,8,9,10]" > λ> read it :: [Int] > [1,2,3,4,5,6,7,8,9,10] > > tl;dr: cheap type parsing. For any more specialised/complex parsing, > use a proper parsing library like Parsec. > _______________________________________________ > 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 Tue Jul 17 08:48:33 2018 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Tue, 17 Jul 2018 08:48:33 +0000 Subject: [Haskell-beginners] forkProcess behaviour Message-ID: Hello, I try to write a service which execute an IO using forkProcess This service contain a web server whcih avwait for job published by users. for each job, I create a forkProcess of this job. I need to fork the process in order to change the uid and gid of the process for each of the job dependencing on who request the job. I have a least two questions 1) is this forkProcess a fork of all the current process, or is it just an executin of the IO in another process id ? I ask this because sometime one of my job hang and a process keep running. Since the original process is binded to a port, it is not possible to restart the server, saying that the port is already in use. 2 ) How can I catch the exceptions thrown from the child process in order to process them in the parent process. thanks for your help answering these questions. Frederic From toad3k at gmail.com Tue Jul 17 13:53:45 2018 From: toad3k at gmail.com (David McBride) Date: Tue, 17 Jul 2018 09:53:45 -0400 Subject: [Haskell-beginners] forkProcess behaviour In-Reply-To: References: Message-ID: I'm not familiar with forkProcess. As for exception handling, with asynchronous exceptions, it's a pretty in depth topic and I can't say I have any mastery of it. fpcomplete did a talk recently that I suspect could answer most of your questions. https://www.youtube.com/watch?v=T5y8sFmCFnA On Tue, Jul 17, 2018 at 4:48 AM, PICCA Frederic-Emmanuel < frederic-emmanuel.picca at synchrotron-soleil.fr> wrote: > Hello, > > I try to write a service which execute an IO using forkProcess > This service contain a web server whcih avwait for job published by users. > for each job, I create a forkProcess of this job. I need to fork the > process in order to change the uid and gid of the process for each of the > job dependencing on who request the job. > > I have a least two questions > > 1) is this forkProcess a fork of all the current process, or is it just an > executin of the IO in another process id ? > > I ask this because sometime one of my job hang and a process keep running. > Since the original process is binded to a port, it is not possible to > restart the server, saying that the port is already in use. > > 2 ) How can I catch the exceptions thrown from the child process in order > to process them in the parent process. > > thanks for your help answering these questions. > > > 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 Thu Jul 19 07:23:45 2018 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Thu, 19 Jul 2018 07:23:45 +0000 Subject: [Haskell-beginners] forkProcess behaviour In-Reply-To: References: , Message-ID: Hello thanks for the link, I already saw theses slides :) but it seems to me that forkProcess is a different beast :)) From michael at snoyman.com Thu Jul 19 13:58:13 2018 From: michael at snoyman.com (Michael Snoyman) Date: Thu, 19 Jul 2018 16:58:13 +0300 Subject: [Haskell-beginners] forkProcess behaviour In-Reply-To: References: Message-ID: Hi Frederic, Let me give a high level recommendation: don't use forkProcess. It's a very dangerous function, which can result in confusing behavior and impossible-to-debug problems. There are cases where it can be made to work, but (1) it's complicated, (2) I'm not sure anyone has ever figured out all of those caveats, and (3) it's certainly not documented properly. forkProcess is little more than a call to the fork() system call, creating a brand new child process which will run the IO action provided. The runtimes of the two processes will not be connected to each other at all. It would be impossible to, say, throw an exception from a thread in the parent process to a thread in the child process. I could say a lot more about this, but I think I'll just reiterate my original recommendation: don't use forkProcess :) Instead, for this kind of use case of changing user/group IDs, I'd recommend using a normal external process call via the process package[1]. I'm not sure of your use case exactly, but I see three ways of making this work: * Generate two Haskell executables * Put the code for both the parent and child into a single executable, and use command line arguments or env vars to control which behavior is run * If you don't have any real logic in the Haskell code, and instead are just using some other program: you can call that directly HTH, Michael [1] Or the typed-process package instead, which I typically recommend these days. Note that I'm the maintainer of process, but typed-process has a brand new API I think is easier to use correctly. More info at: https://haskell-lang.org/library/typed-process On Tue, Jul 17, 2018 at 3:36 PM PICCA Frederic-Emmanuel < frederic-emmanuel.picca at synchrotron-soleil.fr> wrote: > Hello, > > I try to write a service which execute an IO using forkProcess > This service contain a web server whcih avwait for job published by users. > for each job, I create a forkProcess of this job. I need to fork the > process in order to change the uid and gid of the process for each of the > job dependencing on who request the job. > > I have a least two questions > > 1) is this forkProcess a fork of all the current process, or is it just an > executin of the IO in another process id ? > > I ask this because sometime one of my job hang and a process keep running. > Since the original process is binded to a port, it is not possible to > restart the server, saying that the port is already in use. > > 2 ) How can I catch the exceptions thrown from the child process in order > to process them in the parent process. > > thanks for your help answering these questions. > > > 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 Fri Jul 20 07:19:34 2018 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Fri, 20 Jul 2018 07:19:34 +0000 Subject: [Haskell-beginners] forkProcess behaviour In-Reply-To: References: , Message-ID: > Hi Frederic, Hello Michael Thanks a lot for your informative answer. > Let me give a high level recommendation: don't use forkProcess. It's a very dangerous function, which can result in confusing behavior and impossible-to-debug problems. There are cases where it can be made to work, but (1) it's complicated, (2) I'm not sure anyone has ever figured out all of those caveats, and (3) it's certainly not documented properly. > forkProcess is little more than a call to the fork() system call, creating a brand new child process which will run the IO action provided. The runtimes of the two processes will not be > connected to each other at all. It would be impossible to, say, throw an exception from a thread in the parent process to a thread in the child process. > I could say a lot more about this, but I think I'll just reiterate my original recommendation: don't use forkProcess :) > Instead, for this kind of use case of changing user/group IDs, I'd recommend using a normal external process call via the process package[1]. I'm not sure of your use case exactly, > but I see three ways of making this work: > * Generate two Haskell executables > * Put the code for both the parent and child into a single executable, and use command line arguments or env vars to control which behavior is run > * If you don't have any real logic in the Haskell code, and instead are just using some other program: you can call that directly I am quite close to this model, since I have only once executable and the command line parameters allows to execute the different job like this autoprocessing-exe [exec|submit|server] parameters I start my service via the server command without parameters. Then from another computer, I can submit jobs to that server. And locally I can execute jobs with the exec command. What you proposed is just to execute the autoprocessing-command line with s/submit/exec in order to execute a child process. I think that I can do this. Now sometimes this process hang and I want to add a timeout, can I just use timeout for this purpose. 2) I do not want to have communication between my server process and the child one, so in that case is it worth changing the code in order to use process instead of forkPRocess. With process I will need to had lot's of code in oder to convert my job type into command line. I have for now the right Parser command line -> jobtype, but not the other way around. This is why I used forkProcess et first. Once again thanks for your valuable comments. Frédéric From michael at snoyman.com Tue Jul 24 05:10:48 2018 From: michael at snoyman.com (Michael Snoyman) Date: Tue, 24 Jul 2018 08:10:48 +0300 Subject: [Haskell-beginners] forkProcess behaviour In-Reply-To: References: Message-ID: On Fri, Jul 20, 2018 at 10:19 AM PICCA Frederic-Emmanuel < frederic-emmanuel.picca at synchrotron-soleil.fr> wrote: > > Hi Frederic, > > Hello Michael > > Thanks a lot for your informative answer. > > > Let me give a high level recommendation: don't use forkProcess. It's a > very dangerous function, which can result in confusing behavior and > impossible-to-debug problems. There are cases where it can be made to work, > but (1) it's complicated, (2) I'm not sure anyone has ever figured out all > of those caveats, and (3) it's certainly not documented properly. > > > forkProcess is little more than a call to the fork() system call, > creating a brand new child process which will run the IO action provided. > The runtimes of the two processes will not be > connected to each other at > all. It would be impossible to, say, throw an exception from a thread in > the parent process to a thread in the child process. > > > I could say a lot more about this, but I think I'll just reiterate my > original recommendation: don't use forkProcess :) > > > Instead, for this kind of use case of changing user/group IDs, I'd > recommend using a normal external process call via the process package[1]. > I'm not sure of your use case exactly, > but I see three ways of making > this work: > > > * Generate two Haskell executables > > * Put the code for both the parent and child into a single executable, > and use command line arguments or env vars to control which behavior is run > > * If you don't have any real logic in the Haskell code, and instead are > just using some other program: you can call that directly > > I am quite close to this model, since I have only once executable and the > command line parameters allows to execute the different job like this > > autoprocessing-exe [exec|submit|server] parameters > > I start my service via the server command without parameters. > Then from another computer, I can submit jobs to that server. > And locally I can execute jobs with the exec command. > > What you proposed is just to execute the autoprocessing-command line with > s/submit/exec in order to execute a child process. > > I think that I can do this. > > Now sometimes this process hang and I want to add a timeout, can I just > use timeout for this purpose. > > For the most part, yes. You may need to reach deeper and use SIGKILL occasionally, depending on how stubborn the child process is. The `timeout` will only kill off the parent thread's call to block on the child's exit code. > 2) I do not want to have communication between my server process and the > child one, so in that case is it worth changing the code in order to use > process instead of forkPRocess. > > With process I will need to had lot's of code in oder to convert my job > type into command line. > > I have for now the right Parser command line -> jobtype, but not the other > way around. > This is why I used forkProcess et first. > > Once again thanks for your valuable comments. > > Yes, you should avoid forkProcess in this case, it will have unpredictable and confusing results. > Frédéric > _______________________________________________ > 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 Tue Jul 24 07:05:18 2018 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Tue, 24 Jul 2018 07:05:18 +0000 Subject: [Haskell-beginners] forkProcess behaviour In-Reply-To: References: , Message-ID: Hello I have done the first solution and call the program changing the command line in oder to execute each child task. It works well and I can change the uid gid of these process. > For the most part, yes. You may need to reach deeper and use SIGKILL occasionally, depending on how stubborn the child process is. The `timeout` will only kill off the parent thread's call to block on the child's exit code. Since all these tasks are executing also child process via other system cals. So I have a hyerarchy of process. Do you know how to manage that sort of things if something goes wrong and I need to kill the first child and all its children's ? Is it possible for CreateProcess to track all these process and kill them all on request ? > Yes, you should avoid forkProcess in this case, it will have unpredictable and confusing results. I take you advices seriously and now I start to build something (I hope) more robust. Thansk Frédéric From michael at snoyman.com Wed Jul 25 08:23:25 2018 From: michael at snoyman.com (Michael Snoyman) Date: Wed, 25 Jul 2018 11:23:25 +0300 Subject: [Haskell-beginners] forkProcess behaviour In-Reply-To: References: Message-ID: On Tue, Jul 24, 2018 at 10:05 AM PICCA Frederic-Emmanuel < frederic-emmanuel.picca at synchrotron-soleil.fr> wrote: > Hello > > I have done the first solution and call the program changing the command > line in oder to execute each child task. > It works well and I can change the uid gid of these process. > > > For the most part, yes. You may need to reach deeper and use SIGKILL > occasionally, depending on how stubborn the child process is. The `timeout` > will only kill off the parent thread's call to block on the child's exit > code. > > Since all these tasks are executing also child process via other system > cals. > So I have a hyerarchy of process. > > Do you know how to manage that sort of things if something goes wrong and > I need to kill the first child and all its children's ? > Is it possible for CreateProcess to track all these process and kill them > all on request ? > > Funnily enough, there's another discussion going on about this right now: https://mail.haskell.org/pipermail/haskell-cafe/2018-July/129646.html The basic answer is: * You can create a process group and then kill the whole process group * But a misbehaving program would still be able to escape it by creating its own process group, only something like cgroups can be fully reliable here > > Yes, you should avoid forkProcess in this case, it will have > unpredictable and confusing results. > > I take you advices seriously and now I start to build something (I hope) > more robust. > > Thansk > > Frédéric > _______________________________________________ > 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 Wed Jul 25 08:26:47 2018 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Wed, 25 Jul 2018 08:26:47 +0000 Subject: [Haskell-beginners] forkProcess behaviour In-Reply-To: References: , Message-ID: > Funnily enough, there's another discussion going on about this right now: > https://mail.haskell.org/pipermail/haskell-cafe/2018-July/129646.html :)) > The basic answer is: > * You can create a process group and then kill the whole process group > * But a misbehaving program would still be able to escape it by creating its own process group, only something like cgroups can be fully reliable here My server will be managed via systemd, so I hope that it will be able to managed this when restarting. Is there an haskell API in order to work with cgoups ? Cheers Fred From michael at snoyman.com Wed Jul 25 08:28:05 2018 From: michael at snoyman.com (Michael Snoyman) Date: Wed, 25 Jul 2018 11:28:05 +0300 Subject: [Haskell-beginners] forkProcess behaviour In-Reply-To: References: Message-ID: On Wed, Jul 25, 2018 at 11:27 AM PICCA Frederic-Emmanuel < frederic-emmanuel.picca at synchrotron-soleil.fr> wrote: > > Funnily enough, there's another discussion going on about this right now: > > > https://mail.haskell.org/pipermail/haskell-cafe/2018-July/129646.html > > > :)) > > > The basic answer is: > > > * You can create a process group and then kill the whole process group > > * But a misbehaving program would still be able to escape it by creating > its own process group, only something like cgroups can be fully reliable > here > > My server will be managed via systemd, so I hope that it will be able to > managed this when restarting. > Is there an haskell API in order to work with cgoups ? > > None that I'm aware of. > Cheers > > Fred > _______________________________________________ > 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 50295 at web.de Thu Jul 26 01:44:55 2018 From: 50295 at web.de (Olumide) Date: Thu, 26 Jul 2018 02:44:55 +0100 Subject: [Haskell-beginners] Where is the accumulator in the expression foldr (<=<) return (replicate x oveKnight)? -- from LYAH example Message-ID: <8d3be724-8f53-0bdb-339f-b713140ae673@web.de> Dear List, Chapter 13 of LYAH (http://learnyouahaskell.com/for-a-few-monads-more#useful-monadic-functions) has the following code block import Data.List inMany :: Int -> KnightPos -> [KnightPos] inMany x start = return start >>= foldr (<=<) return (replicate x oveKnight) What I'd like to know is where the accumulator of foldr is in this example. Regards, - Olumide From utprimum at gmail.com Thu Jul 26 06:11:28 2018 From: utprimum at gmail.com (Ut Primum) Date: Thu, 26 Jul 2018 08:11:28 +0200 Subject: [Haskell-beginners] Where is the accumulator in the expression foldr (<=<) return (replicate x oveKnight)? -- from LYAH example In-Reply-To: <8d3be724-8f53-0bdb-339f-b713140ae673@web.de> References: <8d3be724-8f53-0bdb-339f-b713140ae673@web.de> Message-ID: Hi, Looking at the structure of the expression, you should have foldr operator accumulator list So in your example the accumulator should be "return" (because it is the second argument) Il gio 26 lug 2018, 03:45 Olumide <50295 at web.de> ha scritto: > Dear List, > > Chapter 13 of LYAH > ( > http://learnyouahaskell.com/for-a-few-monads-more#useful-monadic-functions) > > has the following code block > > import Data.List > > inMany :: Int -> KnightPos -> [KnightPos] > inMany x start = return start >>= foldr (<=<) return (replicate x > oveKnight) > > What I'd like to know is where the accumulator of foldr is in this example. > > Regards, > > - Olumide > > > > > _______________________________________________ > 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 aquagnu at gmail.com Thu Jul 26 06:14:07 2018 From: aquagnu at gmail.com (Paul) Date: Thu, 26 Jul 2018 09:14:07 +0300 Subject: [Haskell-beginners] Where is the accumulator in the expression foldr (<=<) return (replicate x oveKnight)? -- from LYAH example In-Reply-To: <8d3be724-8f53-0bdb-339f-b713140ae673@web.de> References: <8d3be724-8f53-0bdb-339f-b713140ae673@web.de> Message-ID: <69c4a3db-de78-6fc3-dbc7-2a0efc10a479@gmail.com> Hello, `return` is the initial value. So, `replicate x oveKnignt)` is a list of functions. `foldr` folds them with initial value `return` with the `<=<` between them: functions are folding with (<=<). First folding value is `return` function. You can check the types with :t something in the GHCi. Result of folding is flow of functions or long functions circuit. `return start` is the same as to pass `start` to this functions circuit: inMany x start = foldr (<=<) return (replicate x oveKnight) $ start Idea seems, to make from [KnighPos -> [KnighPos]] functions list one function: KnighPos -> [KnighPos] performing those functions step by step (<=<) and to pass `start` to it. Due to `<=<`  joining of functions is not "do", but "do for each...", because <=< is in the list monad. Something like: for x in f-last start:   for y in f-prelast x:     ... You can look at these types: :t foldr foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b  :t (<=<) (<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c 26.07.2018 04:44, Olumide wrotes: > Dear List, > > Chapter 13 of LYAH > (http://learnyouahaskell.com/for-a-few-monads-more#useful-monadic-functions) > has the following code block > > import Data.List > > inMany :: Int -> KnightPos -> [KnightPos] > inMany x start = return start >>= foldr (<=<) return (replicate x > oveKnight) > > What I'd like to know is where the accumulator of foldr is in this > example. > > Regards, > > - Olumide > > > > > _______________________________________________ > 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 tonymorris at gmail.com Fri Jul 27 03:29:31 2018 From: tonymorris at gmail.com (Tony Morris) Date: Fri, 27 Jul 2018 13:29:31 +1000 Subject: [Haskell-beginners] Where is the accumulator in the expression foldr (<=<) return (replicate x oveKnight)? -- from LYAH example In-Reply-To: <8d3be724-8f53-0bdb-339f-b713140ae673@web.de> References: <8d3be724-8f53-0bdb-339f-b713140ae673@web.de> Message-ID: foldr does not involve an accumulator. Only left folds involve an accumulator. Specifically, the expression: foldl f z list can be though of as this loop: var r = z foreach(element in list) {   r = f(r, element) } return r That is why, for example, foldl (\r element -> element : r) [] will reverse a list. The accumulator here is the (r) value in the loop. The foldr function does constructor replacement, and in no prescribed order. The expression foldr f z list will replace every (:) with (f) and [] with (z) in list. So the expression foldr (<=<) return will take a list, such as thing one: let list = a : b : c : d : e : [] and turn it into this value: foldr (<=<) return list = a <=< b <=< c <=< d <=< e <=< return This will occur in no prescribed order, although the replacement is right-associative. It is often said that foldr "starts at the right-most", however, this is untrue, since foldr works on infinite list, which has no notion of right-most. Importantly, there is no notion of "accumulator" here, only constructor replacement. The right-associativity simply means that the parentheses are to the right: a <=< (b <=< (c <=< (d <=< (e <=< return)))) However, this does not necessarily impose an execution order, or accumulator. Consider this expression: foldr const (repeat 1) This will produce the value: 1 `const` (1 `const` (1 `const` 1 ... The result of normalising this expression produces the value 1. There is no notion of the "right-most" to "accumulate" anything. It simply evaluates and the answer is 1. On 07/26/2018 11:44 AM, Olumide wrote: > Dear List, > > Chapter 13 of LYAH > (http://learnyouahaskell.com/for-a-few-monads-more#useful-monadic-functions) > has the following code block > > import Data.List > > inMany :: Int -> KnightPos -> [KnightPos] > inMany x start = return start >>= foldr (<=<) return (replicate x > oveKnight) > > What I'd like to know is where the accumulator of foldr is in this > example. > > Regards, > > - Olumide > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: OpenPGP digital signature URL: From frederic-emmanuel.picca at synchrotron-soleil.fr Sun Jul 29 08:56:43 2018 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Sun, 29 Jul 2018 08:56:43 +0000 Subject: [Haskell-beginners] Best way to trig an IO action on a condition. Message-ID: Hello, Now that I know how to fork a process the right way :) I would like to trig this process when a list of file exist on the system. I can not use inotify since my files are on an nfs sytem. So I would like your advices in order to create a Condition which wait for the presence of these files and when this condition is fullliled, trigg the action. Thanks for your help. Frederic. From simon.jakobi at googlemail.com Sun Jul 29 11:18:03 2018 From: simon.jakobi at googlemail.com (Simon Jakobi) Date: Sun, 29 Jul 2018 13:18:03 +0200 Subject: [Haskell-beginners] Best way to trig an IO action on a condition. In-Reply-To: References: Message-ID: Hi Frederic, fsnotify seems like it should work on Windows: http://hackage.haskell.org/package/fsnotify Cheers, Simon Am So., 29. Juli 2018 um 11:08 Uhr schrieb PICCA Frederic-Emmanuel < frederic-emmanuel.picca at synchrotron-soleil.fr>: > Hello, > > Now that I know how to fork a process the right way :) > I would like to trig this process when a list of file exist on the system. > > I can not use inotify since my files are on an nfs sytem. > > So I would like your advices in order to create a Condition which wait for > the presence of these files and when this condition is fullliled, trigg the > action. > > 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: