From shishir.srivastava at gmail.com Fri May 1 12:40:16 2015 From: shishir.srivastava at gmail.com (Shishir Srivastava) Date: Fri, 1 May 2015 13:40:16 +0100 Subject: [Haskell-beginners] Loop Message-ID: Hi, Please can anyone point out the correct way of doing this - I am simply trying to print "Test" in a loop based on the counter derived from the list - ---- do _ <- [1..4] b <- putStrLn "Test" return b --- The intended output is to print 'Test' 4 times. Clearly there is a mismatch between the Monad types but I can't see how to achieve this without causing the conflict. Thanks, Shishir -------------- next part -------------- An HTML attachment was scrubbed... URL: From marcin.jan.mrotek at gmail.com Fri May 1 13:08:26 2015 From: marcin.jan.mrotek at gmail.com (Marcin Mrotek) Date: Fri, 1 May 2015 15:08:26 +0200 Subject: [Haskell-beginners] Loop In-Reply-To: References: Message-ID: Hello, First of all, putStrLn has type IO (), so b is pretty useless in your code, it's going to have type (), and the only value of this type is (). The simplest way to perform some action based on a list and discard the results is mapM_: mapM_ (\_ -> putStrLn "Test") [1..4] though if you discard the list's elements too, you can use sequence_ and replicate instead: sequence_ . replicate 4 $ putStrLn "Test" As a side note, if you actually want to combine monads (like list and IO) you can use monad transformers. The ListT type from transformers library has some issues as far as I know, but you can use the one from pipes, for example. Have a look at: http://www.haskellforall.com/2014/11/how-to-build-library-agnostic-streaming.html Best regards, Marcin Mrotek From sumit.sahrawat.apm13 at iitbhu.ac.in Fri May 1 13:09:39 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Fri, 1 May 2015 18:39:39 +0530 Subject: [Haskell-beginners] Loop In-Reply-To: References: Message-ID: putStrLn "Test" is a IO value, that prints the string "Test". To sequence such monadic values, we use sequence or sequence_ (which ignores the results). "sequence [a, b, c, d]" is equivalent to "a >> b >> c >> d" "sequence_ [a, b, c, d]" is equivalent to "a >> b >> c >> d >> return ()" There are similar functions mapM and mapM_, which can be used as follows. mapM f [a, b, c] == sequence (map f [a,b,c]) == sequence [f a, f b, f c] == f a >> f b >> f c and, mapM_ f [a, b, c] == f a >> f b >> f c >> return () >From mapM_, we can create a convenience function forM_ forM_ = flip mapM_ All the above are exported by Control.Monad On 1 May 2015 at 18:10, Shishir Srivastava wrote: > Hi, > > Please can anyone point out the correct way of doing this - I am simply > trying to print "Test" in a loop based on the counter derived from the list > - > > ---- > do > _ <- [1..4] > b <- putStrLn "Test" > return b > --- > > The intended output is to print 'Test' 4 times. > > Clearly there is a mismatch between the Monad types but I can't see how to > achieve this without causing the conflict. > > Thanks, > Shishir > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From shishir.srivastava at gmail.com Fri May 1 13:12:15 2015 From: shishir.srivastava at gmail.com (Shishir Srivastava) Date: Fri, 1 May 2015 14:12:15 +0100 Subject: [Haskell-beginners] Loop Message-ID: Hi Marcin, Thanks for your response. Yes my intention to use 'do' was to implement it in so called 'imperative' style coding. So if I understand it correctly there is no other way to achieve it via 'do' w/o using the monad transformers? Thanks again Shishir -------------- next part -------------- An HTML attachment was scrubbed... URL: From marcin.jan.mrotek at gmail.com Fri May 1 14:23:51 2015 From: marcin.jan.mrotek at gmail.com (Marcin Mrotek) Date: Fri, 1 May 2015 16:23:51 +0200 Subject: [Haskell-beginners] Loop In-Reply-To: References: Message-ID: It depends on what are you trying to achieve. The ListT monad transformer is an overkill for your example, as you don't use the "non-determinism" feature of ListT (code written using it can use whole lists of values as if it was one value with multiple "versions", any action can return any number of results, which are then combined together, perhaps without even calculating all of them if they're not needed); if you just want to sequence actions, it's enough to use mapM, mapM_, sequence, sequence_, and other functions from Control.Monad. But if you have something more complicated in mind, it might be worth taking a look at ListT and other transformers to see if they can be of any use to you. Best regards, Marcin Mrotek From amindfv at gmail.com Fri May 1 17:36:42 2015 From: amindfv at gmail.com (amindfv at gmail.com) Date: Fri, 1 May 2015 13:36:42 -0400 Subject: [Haskell-beginners] Loop In-Reply-To: References: Message-ID: <65200A72-5428-47A1-95FA-DEDEF8E77A59@gmail.com> What you really want is "replicateM_". But to answer your original question, you could do something like: import Control.Monad.List main = runListT $ do _ <- ListT $ pure [1,2,3,4] liftIO $ putStrLn "Test" (replicateM_ is way better though) Tom El May 1, 2015, a las 10:23, Marcin Mrotek escribi?: > It depends on what are you trying to achieve. The ListT monad > transformer is an overkill for your example, as you don't use the > "non-determinism" feature of ListT (code written using it can use > whole lists of values as if it was one value with multiple "versions", > any action can return any number of results, which are then combined > together, perhaps without even calculating all of them if they're not > needed); if you just want to sequence actions, it's enough to use > mapM, mapM_, sequence, sequence_, and other functions from > Control.Monad. But if you have something more complicated in mind, it > might be worth taking a look at ListT and other transformers to see if > they can be of any use to you. > > Best regards, > Marcin Mrotek > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From marcin.jan.mrotek at gmail.com Fri May 1 20:09:44 2015 From: marcin.jan.mrotek at gmail.com (Marcin Mrotek) Date: Fri, 1 May 2015 22:09:44 +0200 Subject: [Haskell-beginners] Loop In-Reply-To: <65200A72-5428-47A1-95FA-DEDEF8E77A59@gmail.com> References: <65200A72-5428-47A1-95FA-DEDEF8E77A59@gmail.com> Message-ID: Ah, sorry, I forgot about replicateM_. Best regards, Marcin Mrotek From sumit.sahrawat.apm13 at iitbhu.ac.in Sat May 2 00:06:47 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Sat, 2 May 2015 05:36:47 +0530 Subject: [Haskell-beginners] Loop In-Reply-To: References: <65200A72-5428-47A1-95FA-DEDEF8E77A59@gmail.com> Message-ID: The reply I gave before might be more helpful if you consider the fact that a >> b >> c is equivalent to do a b c You can then use forM_ [1..4] (\_ -> putStrLn "Test") What this does is, 1. map (\_ -> putStrLn "Test") on [1..4] 2. Use sequence_ to combine those operations The even shorter way is replicateM_ which works like replicate from Data.List On 2 May 2015 at 01:39, Marcin Mrotek wrote: > Ah, sorry, I forgot about replicateM_. > > Best regards, > Marcin Mrotek > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From florian.gillard at gmail.com Sat May 2 13:19:48 2015 From: florian.gillard at gmail.com (Florian Gillard) Date: Sat, 2 May 2015 15:19:48 +0200 Subject: [Haskell-beginners] Haskell ghc, linking error when trying to compile a program using ghc and Euterpea Message-ID: I am checking out the computing music development library Euterpea, and I am trying to compile the following basic program: import Euterpea t251 :: Music Pitch t251 = let dMinor = d 4 wn :=: f 4 wn :=: a 4 wn gMajor = g 4 wn :=: b 4 wn :=: d 5 wn cMajor = c 4 bn :=: e 4 bn :=: g 4 bn in dMinor :+: gMajor :+: cMajor main = play t251 the program works fine inside ghci, but when I try to compile it using ghc test.hs I get the following error message: Linking test ... /usr/bin/ld: /home/fayong/.cabal/lib/PortMidi-0.1.3/ghc-7.6.3/libHSPortMidi-0.1.3.a(ptlinux.o): undefined reference to symbol 'pthread_create@@GLIBC_2.2.5' //lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status It seems to be a linking error but I don't know how to fix it. (I tried to pass -lpthread as an option but it didn't work) I installed Euterpea via cabal, on linux mint 17 -------------- next part -------------- An HTML attachment was scrubbed... URL: From k-bx at k-bx.com Sun May 3 08:04:59 2015 From: k-bx at k-bx.com (Kostiantyn Rybnikov) Date: Sun, 3 May 2015 11:04:59 +0300 Subject: [Haskell-beginners] : GCJ 2015 - Round 1A Problem - Haircut In-Reply-To: <08EF9DA445C4B5439C4733E1F35705BA04F834A3C7D7@MAIL.cs.mum.edu> References: <08EF9DA445C4B5439C4733E1F35705BA04F834A3C7D7@MAIL.cs.mum.edu> Message-ID: Instead of looking at it as an estimate, you can look at it as a "summarized speed of all barbers". It would let you know much time would it take to cut everyone before you. Afterwards you'd need to go through barbers and find the first one that would become available after this time-period. Do you think this makes sense? 27 ????. 2015 05:40 "Gregory Guthrie" ????: > Seems to me that an estimate won't help, one has to know exactly how much > to skip over. > > I did this: > Find the lowest common multiple (lcm), and then from that the shortest > cycle of services, > And then skip any multiple of those from the customer queue. > > sim :: Problem -> [Result] > sim (n, ts) = serve tSkip (servers ts) > -- optimize; skip ahead over server cycles... > where tsLcm = (foldl lcm $ head ts) $ tail ts > tCycle = sum $ map (div tsLcm) ts > tSkip = n - (div n tCycle)*tCycle > > (Some fixup is needed for tSkip=0, one easy one is to force an extra > cycle.) > > ---------------------------------------------------------------------- > > Message: 1 > > Date: Sat, 18 Apr 2015 10:29:11 -0400 > > From: Doug McIlroy > > To: sourabh.s.joshi at gmail.com > > Cc: beginners at haskell.org > > Subject: Re: [Haskell-beginners] GCJ 2015 - Round 1A Problem - Haircut > > Message-ID: <201504181429.t3IETBfo025201 at coolidge.cs.dartmouth.edu> > > Content-Type: text/plain; charset=us-ascii > > > > > Can someone tell me how I could have avoided or fixed this? > > > > The trouble manifested as stack overflow on solving > > > > > https://code.google.com/codejam/contest/4224486/dashboard#s=p1 > > > > For efficiency, you'll probably need more cleverness in math than in > Haskell. You can predict > > an approximate start time for the Nth customer's service from the > average per-customer > > service time M, where 1/M = sum 1/M_k. > > Starting from that estimate, one can skip over almost the entire service > simulation. > > > > Doug McIlroy > > > > > _______________________________________________ > 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 stf.list.haskell at eisenbits.com Sun May 3 10:48:09 2015 From: stf.list.haskell at eisenbits.com (Stanislaw Findeisen) Date: Sun, 03 May 2015 12:48:09 +0200 Subject: [Haskell-beginners] definition of >>= for lists Message-ID: <5545FCE9.3080006@eisenbits.com> Hi Where is the definition of (>>=) for lists? I was trying to locate it using Hoogle but no luck. :( -- http://people.eisenbits.com/~stf/ http://www.eisenbits.com/ OpenPGP: 9EC2 5620 2355 B1DC 4A8F 8C79 0EC7 C214 E5AE 3B4E -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From eriknstevenson at gmail.com Sun May 3 11:03:50 2015 From: eriknstevenson at gmail.com (Erik Stevenson) Date: Sun, 3 May 2015 07:03:50 -0400 Subject: [Haskell-beginners] definition of >>= for lists In-Reply-To: <5545FCE9.3080006@eisenbits.com> References: <5545FCE9.3080006@eisenbits.com> Message-ID: Hi, instance Monad [] where {-# INLINE (>>=) #-} xs >>= f = [y | x <- xs, y <- f x] {-# INLINE (>>) #-} (>>) = (*>) {-# INLINE return #-} return x = [x] {-# INLINE fail #-} fail _ = [] source: https://hackage.haskell.org/package/base-4.8.0.0/docs/src/GHC-Base.html#line-726 Found link on: https://hackage.haskell.org/package/base-4.8.0.0/docs/Control-Monad.html by scrolling down to the list of monad instances. On Sun, May 3, 2015 at 6:48 AM, Stanislaw Findeisen < stf.list.haskell at eisenbits.com> wrote: > Hi > > Where is the definition of (>>=) for lists? I was trying to locate it > using Hoogle but no luck. :( > > -- > http://people.eisenbits.com/~stf/ > http://www.eisenbits.com/ > > OpenPGP: 9EC2 5620 2355 B1DC 4A8F 8C79 0EC7 C214 E5AE 3B4E > > > _______________________________________________ > 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 stf.list.haskell at eisenbits.com Sun May 3 11:02:22 2015 From: stf.list.haskell at eisenbits.com (Stanislaw Findeisen) Date: Sun, 03 May 2015 13:02:22 +0200 Subject: [Haskell-beginners] Variable re-use In-Reply-To: References: <553F5CFA.9040503@gmail.com> Message-ID: <5546003E.8020404@eisenbits.com> On 2015-04-28 12:15, Alexey Shmalko wrote: > I'm sorry, my example should've been: > > [1,2,3] >>= \a -> [a+1] >>= \a -> return a Or just: [1,2,3] >>= (return . (+1)) -- http://people.eisenbits.com/~stf/ http://www.eisenbits.com/ OpenPGP: 9EC2 5620 2355 B1DC 4A8F 8C79 0EC7 C214 E5AE 3B4E -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From rasen.dubi at gmail.com Sun May 3 18:19:25 2015 From: rasen.dubi at gmail.com (Alexey Shmalko) Date: Sun, 3 May 2015 21:19:25 +0300 Subject: [Haskell-beginners] Variable re-use In-Reply-To: <5546003E.8020404@eisenbits.com> References: <553F5CFA.9040503@gmail.com> <5546003E.8020404@eisenbits.com> Message-ID: On Sun, May 3, 2015 at 2:07 PM Stanislaw Findeisen < stf.list.haskell at eisenbits.com> wrote: > On 2015-04-28 12:15, Alexey Shmalko wrote: > > I'm sorry, my example should've been: > > > > [1,2,3] >>= \a -> [a+1] >>= \a -> return a > > Or just: > > [1,2,3] >>= (return . (+1)) > Or just: [2,3,4] The point of the example was to desugar original do notation and show there are two `a`s involved. -------------- next part -------------- An HTML attachment was scrubbed... URL: From shishir.srivastava at gmail.com Tue May 5 15:19:03 2015 From: shishir.srivastava at gmail.com (Shishir Srivastava) Date: Tue, 5 May 2015 16:19:03 +0100 Subject: [Haskell-beginners] Data type Message-ID: Hi, Could anyone please have a look and let me know how you can create the instance of this data type ? --- data Person = Person { firstName ::String -> Int } --- I've seen this type of syntax in a lot of places in haskell code where a new data type is defined in terms of functions rather than concrete data types. I am not trying to achieve anything out of this but purely as an exercise in understanding the record syntax. As far as I understand the data type is function based and takes a 'function' instead of a value of a concrete type so how does one create an instance of this type. Thanks, Shishir -------------- next part -------------- An HTML attachment was scrubbed... URL: From matthewmoppett at gmail.com Tue May 5 15:23:53 2015 From: matthewmoppett at gmail.com (Matthew Moppett) Date: Tue, 5 May 2015 22:23:53 +0700 Subject: [Haskell-beginners] Data type In-Reply-To: References: Message-ID: Here's a quick example using ghci: Prelude> let a = Person length Prelude> :type a a :: Person Prelude> (firstName a) "Bob" 3 On Tue, May 5, 2015 at 10:19 PM, Shishir Srivastava < shishir.srivastava at gmail.com> wrote: > Hi, > > Could anyone please have a look and let me know how you can create the > instance of this data type ? > > --- > data Person = Person { firstName ::String -> Int } > --- > > I've seen this type of syntax in a lot of places in haskell code where a > new data type is defined in terms of functions rather than concrete data > types. > > I am not trying to achieve anything out of this but purely as an exercise > in understanding the record syntax. > > As far as I understand the data type is function based and takes a > 'function' instead of a value of a concrete type so how does one create an > instance of this type. > > Thanks, > Shishir > > _______________________________________________ > 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 shishir.srivastava at gmail.com Tue May 5 15:28:08 2015 From: shishir.srivastava at gmail.com (Shishir Srivastava) Date: Tue, 5 May 2015 16:28:08 +0100 Subject: [Haskell-beginners] Data type Message-ID: Thanks Matthew - that was crisp ! Cheers, Shishir -------------- next part -------------- An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Tue May 5 15:28:24 2015 From: allbery.b at gmail.com (Brandon Allbery) Date: Tue, 5 May 2015 11:28:24 -0400 Subject: [Haskell-beginners] Data type In-Reply-To: References: Message-ID: On Tue, May 5, 2015 at 11:19 AM, Shishir Srivastava < shishir.srivastava at gmail.com> wrote: > As far as I understand the data type is function based and takes a > 'function' instead of a value of a concrete type so how does one create an > instance of this type. Functions are first class and fairly concrete (unless polymorphic) in functional languages. (But I wonder at your example as it seems pretty strange to have firstName be String -> Int.) Person { firstName = \name -> whatever } Person { firstName = length } Practical example from xmonad-contrib: logHook = dynamicLogWithPP $ defaultPP { ppOutput = hPutStrLn dock } (two such fields for the price of one! logHook and ppOutput are both function-valued) where dock is from a spawnPipe call that launches something like dzen or xmobar with a pipe connected to its stdin. (See http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-DynamicLog.html#g:1 ) It is worth remembering lazy evaluation; the functions are not evaluated at the time of assignment. -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From shishir.srivastava at gmail.com Tue May 5 15:38:11 2015 From: shishir.srivastava at gmail.com (Shishir Srivastava) Date: Tue, 5 May 2015 16:38:11 +0100 Subject: [Haskell-beginners] Data type Message-ID: Hi Brandon, Thanks for your response. My example was just a bad turnout which I conjured up using tutorials and playing with it. I was going to follow up my question with the possible practical use of why and where someone would use such a construct to wrap a function inside a new data-type. For all that matters I could have used 'length' function directly to get the same output. I appreciate that you already have given the practical example but anything more basic for beginners to highlight the usage would be helpful. Thanks, Shishir On Tue, May 5, 2015 at 4:28 PM, Shishir Srivastava < shishir.srivastava at gmail.com> wrote: > Thanks Matthew - that was crisp ! > > Cheers, > Shishir > -------------- next part -------------- An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Tue May 5 15:49:58 2015 From: allbery.b at gmail.com (Brandon Allbery) Date: Tue, 5 May 2015 11:49:58 -0400 Subject: [Haskell-beginners] Data type In-Reply-To: References: Message-ID: On Tue, May 5, 2015 at 11:38 AM, Shishir Srivastava < shishir.srivastava at gmail.com> wrote: > I was going to follow up my question with the possible practical use of > why and where someone would use such a construct to wrap a function inside > a new data-type. > > For all that matters I could have used 'length' function directly to get > the same output. > Because you want a different function for each value, typically. Continuing with the DynamicLog example, I have two different uses of DynamicLog in my xmonad config; one feeds an EWMH panel from the logHook, so it sets defaultPP { {- ... -}, ppOutput = dbusOutput ch } where ch was previously associated with a dbus endpoint. This is executed whenever the focused window changes or the current workspace changes. The second is in a keybinding I use for debugging and outputs to the session log (~/.xsession-errors): defaultPP { {- ... -}, ppOutput = hPutStrLn stderr } (The ellipsis comments customize the value in other ways not important here.) You might think of this use of record syntax as being the Haskell version of "named parameters" (as distinct from positional parameters) present in some other languages. -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From ahammel87 at gmail.com Tue May 5 16:11:00 2015 From: ahammel87 at gmail.com (Alex Hammel) Date: Tue, 05 May 2015 16:11:00 +0000 Subject: [Haskell-beginners] Data type In-Reply-To: References: Message-ID: Sticking with the Person example, we might want to use a dynamically-bound function to specify a different greeting message for different values of Person: data Person = Person { name :: String , greet :: Person -> String } anne = Person "Anne" (\p -> "Howdy, " ++ name p ++ ".") bob = Person "Bob" (\p -> "Hi, " ++ name p ++ "! I'm Bob") carol = Person "Carol" (\_ -> "'Sup?") main = do putStrLn $ anne `greet` bob putStrLn $ bob `greet` carol putStrLn $ carol `greet` anne You could even get really crazy and construct the greeting function at runtime: main = do putStr "Enter a name: " n <- getLine putStrL"Enter a greeting: " greeting <- getLine let user = Person n (\p -> concat [greeting, ", ", name p, "!"]) bob = Person "Bob" (\p -> concat ["Hello, ", name p, "!"]) putStrLn $ bob `greet` user putStrLn $ user `greet` bob $ runhaskell test.hs Enter a name: Morbo Enter a greeting: I WILL DESTROY YOU Hello, Morbo! I WILL DESTROY YOU, Bob! On Tue, 5 May 2015 at 08:38 Shishir Srivastava wrote: > Hi Brandon, > > Thanks for your response. My example was just a bad turnout which I > conjured up using tutorials and playing with it. > > I was going to follow up my question with the possible practical use of > why and where someone would use such a construct to wrap a function inside > a new data-type. > > For all that matters I could have used 'length' function directly to get > the same output. > > I appreciate that you already have given the practical example but > anything more basic for beginners to highlight the usage would be helpful. > > Thanks, > Shishir > > > On Tue, May 5, 2015 at 4:28 PM, Shishir Srivastava < > shishir.srivastava at gmail.com> wrote: > >> Thanks Matthew - that was crisp ! >> >> Cheers, >> Shishir >> > > _______________________________________________ > 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 vale.cofershabica at gmail.com Tue May 5 17:43:48 2015 From: vale.cofershabica at gmail.com (Vale Cofer-Shabica) Date: Tue, 5 May 2015 13:43:48 -0400 Subject: [Haskell-beginners] Unix-style command line arguments and file input? Message-ID: Hello all, Punchline first: What's the "best practice" way of doing unix-style command line argument and file input processing in Haskell? Background: I'm using Haskell to write programs that act like well-behaved, pipe-friendly unix tools. i.e., the following are all equivalent: % ./prog file % ./prog < file % cat file | ./prog Thus far, I've done this by directly inspecting the first element of System.Environment.getArgs, which has been fine thus far. I'd also like to be able to take simple command line arguments (boolean flags and numeric parameters) and the above doesn't adapt well to that case. I'd like to do this in the idiomatic, "standard" way (a la getopt() in C). Browsing through the wiki page on command line argument parsers [1] gave me a bewildering array of options. I'm not really sure where to start, though I remember reading a blanket endorsement of optparse-applicative somewhere. Any pointers or examples that address my use-case would be much appreciated. -vale [1]: https://wiki.haskell.org/Command_line_option_parsers From michael at orlitzky.com Tue May 5 17:58:58 2015 From: michael at orlitzky.com (Michael Orlitzky) Date: Tue, 05 May 2015 13:58:58 -0400 Subject: [Haskell-beginners] Unix-style command line arguments and file input? In-Reply-To: References: Message-ID: <554904E2.6080707@orlitzky.com> On 05/05/2015 01:43 PM, Vale Cofer-Shabica wrote: > Hello all, > > Punchline first: What's the "best practice" way of doing unix-style > command line argument and file input processing in Haskell? > > Background: > I'm using Haskell to write programs that act like well-behaved, > pipe-friendly unix tools. i.e., the following are all equivalent: > > % ./prog file > % ./prog < file > % cat file | ./prog > > Thus far, I've done this by directly inspecting the first element of > System.Environment.getArgs, which has been fine thus far. > I use CmdArgs for this. I think the simplest example is, https://hackage.haskell.org/package/email-validator And one with multiple modes: https://hackage.haskell.org/package/hath It's not *quite* what you asked for: I use e.g. `hath -i file` to mean the same thing as `hath < file`, but that's as close as I got. From mwm at mired.org Tue May 5 18:07:43 2015 From: mwm at mired.org (Mike Meyer) Date: Tue, 5 May 2015 13:07:43 -0500 Subject: [Haskell-beginners] Unix-style command line arguments and file input? In-Reply-To: <554904E2.6080707@orlitzky.com> References: <554904E2.6080707@orlitzky.com> Message-ID: On Tue, May 5, 2015 at 12:58 PM, Michael Orlitzky wrote: > I use CmdArgs for this. I think the simplest example is, > > https://hackage.haskell.org/package/email-validator > > And one with multiple modes: > > https://hackage.haskell.org/package/hath > > It's not *quite* what you asked for: I use e.g. `hath -i file` to mean > the same thing as `hath < file`, but that's as close as I got. > I also use CmdArgs, though I'm not positive it's still the best choice. eddie (http://chiselapp.com/user/mwm/repository/eddie/doc/tip/README.md) correctly handles the cases you want, and in additions makes: $ cat cat file1 file2 file3 | ./prog $ ./prog file1 file2 file3 do the same thing. However, it's a bit complicated, as eddie has multiple interacting options, an accumulating option, and defaults the first argument to an option and the rest to files to be processed. Figure out the simpler examples first. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rmorgan at trystero.is Tue May 5 18:10:38 2015 From: rmorgan at trystero.is (Rianna Morgan) Date: Tue, 05 May 2015 11:10:38 -0700 Subject: [Haskell-beginners] Unix-style command line arguments and file input? In-Reply-To: References: Message-ID: <1430849438.507693.263066569.0284E204@webmail.messagingengine.com> Hi there, I've had fun using cmdargs[1]. Here are several sites that I found to be very helpful in learning how to use the package: - This was probably the single most helpful bit of example code[2] that I found because it illustrates how to have multiple modes that take different option flags better than other tutorials. - Neil Mitchell, the author of cmdargs, has some nice example[3] code[4] that is also useful for seeing how the library works. - Here is another an example[5] that shows how to make Hello World take a few basic command arguments. Hope this helps, -- Rianna Morgan rmorgan at trystero.is On Tue, May 5, 2015, at 10:43 AM, Vale Cofer-Shabica wrote: > Hello all, > > Punchline first: What's the "best practice" way of doing unix-style > command line argument and file input processing in Haskell? > > Background: I'm using Haskell to write programs that act like > well-behaved, pipe-friendly unix tools. i.e., the following are all > equivalent: > > % ./prog file ./prog < file cat file | ./prog > > Thus far, I've done this by directly inspecting the first element of > System.Environment.getArgs, which has been fine thus far. > > I'd also like to be able to take simple command line arguments > (boolean flags and numeric parameters) and the above doesn't adapt > well to that case. I'd like to do this in the idiomatic, "standard" > way (a la getopt() in C). Browsing through the wiki page on command > line argument parsers [1] gave me a bewildering array of options. I'm > not really sure where to start, though I remember reading a blanket > endorsement of optparse-applicative somewhere. > > Any pointers or examples that address my use-case would be much > appreciated. > > -vale > > [1]: https://wiki.haskell.org/Command_line_option_parsers > _______________________________________________ > Beginners mailing list Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners Links: 1. https://hackage.haskell.org/package/cmdargs 2. https://zuttobenkyou.wordpress.com/2011/04/19/haskell-using-cmdargs-single-and-multi-mode/ 3. http://neilmitchell.blogspot.com/2010/08/cmdargs-example.html 4. http://community.haskell.org/~ndm/cmdargs/ 5. http://spin.atomicobject.com/2012/12/13/using-haskells-cmdargs-package/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Tue May 5 18:12:58 2015 From: toad3k at gmail.com (David McBride) Date: Tue, 5 May 2015 14:12:58 -0400 Subject: [Haskell-beginners] Unix-style command line arguments and file input? In-Reply-To: References: Message-ID: While I used to use cmdargs, at some point I switched to optparse-applicative and never strayed. My only complain about it is that it uses strings everywhere instead of text. On Tue, May 5, 2015 at 1:43 PM, Vale Cofer-Shabica < vale.cofershabica at gmail.com> wrote: > Hello all, > > Punchline first: What's the "best practice" way of doing unix-style > command line argument and file input processing in Haskell? > > Background: > I'm using Haskell to write programs that act like well-behaved, > pipe-friendly unix tools. i.e., the following are all equivalent: > > % ./prog file > % ./prog < file > % cat file | ./prog > > Thus far, I've done this by directly inspecting the first element of > System.Environment.getArgs, which has been fine thus far. > > I'd also like to be able to take simple command line arguments > (boolean flags and numeric parameters) and the above doesn't adapt > well to that case. I'd like to do this in the idiomatic, "standard" > way (a la getopt() in C). Browsing through the wiki page on command > line argument parsers [1] gave me a bewildering array of options. I'm > not really sure where to start, though I remember reading a blanket > endorsement of optparse-applicative somewhere. > > Any pointers or examples that address my use-case would be much > appreciated. > > -vale > > [1]: https://wiki.haskell.org/Command_line_option_parsers > _______________________________________________ > 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 vale.cofershabica at gmail.com Tue May 5 21:22:12 2015 From: vale.cofershabica at gmail.com (Vale Cofer-Shabica) Date: Tue, 5 May 2015 17:22:12 -0400 Subject: [Haskell-beginners] Unix-style command line arguments and file input? In-Reply-To: References: Message-ID: Wow! A big thank you to everyone who responded. I was able to get up and running very rapidly with cmdArgs. The two resources that really got me going were: * http://spin.atomicobject.com/2012/12/13/using-haskells-cmdargs-package/ * https://zuttobenkyou.wordpress.com/2011/04/19/haskell-using-cmdargs-single-and-multi-mode/ I'm going to read through: https://hackage.haskell.org/package/email-validator for ideas now that I understand the basics. eddie looks very interesting; I was longing for something similar recently. Many thanks again, vale On Tue, May 5, 2015 at 2:12 PM, David McBride wrote: > While I used to use cmdargs, at some point I switched to > optparse-applicative and never strayed. My only complain about it is that > it uses strings everywhere instead of text. > > On Tue, May 5, 2015 at 1:43 PM, Vale Cofer-Shabica > wrote: >> >> Hello all, >> >> Punchline first: What's the "best practice" way of doing unix-style >> command line argument and file input processing in Haskell? >> >> Background: >> I'm using Haskell to write programs that act like well-behaved, >> pipe-friendly unix tools. i.e., the following are all equivalent: >> >> % ./prog file >> % ./prog < file >> % cat file | ./prog >> >> Thus far, I've done this by directly inspecting the first element of >> System.Environment.getArgs, which has been fine thus far. >> >> I'd also like to be able to take simple command line arguments >> (boolean flags and numeric parameters) and the above doesn't adapt >> well to that case. I'd like to do this in the idiomatic, "standard" >> way (a la getopt() in C). Browsing through the wiki page on command >> line argument parsers [1] gave me a bewildering array of options. I'm >> not really sure where to start, though I remember reading a blanket >> endorsement of optparse-applicative somewhere. >> >> Any pointers or examples that address my use-case would be much >> appreciated. >> >> -vale >> >> [1]: https://wiki.haskell.org/Command_line_option_parsers >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From cwrseckford at gmail.com Wed May 6 16:05:21 2015 From: cwrseckford at gmail.com (C W Rose) Date: Wed, 6 May 2015 16:05:21 +0000 (UTC) Subject: [Haskell-beginners] Building glib Message-ID: I've been trying to build the glib package (pretty much any version) for a few days now, with no success. The sequence of results is: =================================================================== cwr at sixpence cabal $ cabal --verbose --global --package-db=/opt/cabal/package.conf.d install glib-0.12.5.4 '/opt/cabal/bin/alex' '--version' '/opt/cabal/bin/cpphs' '--version' '/usr/bin/gcc' '-dumpversion' '/opt/cabal/bin/haddock' '--version' '/opt/cabal/bin/happy' '--version' '/usr/bin/hpc' 'version' looking for tool hsc2hs near compiler in /usr/bin found hsc2hs in /usr/bin/hsc2hs '/usr/bin/hsc2hs' '--version' '/opt/cabal/bin/HsColour' '-version' '/usr/bin/ghc' '-c' '/tmp/6826.c' '-o' '/tmp/6826.o' '/usr/bin/ld' '-x' '-r' '/tmp/6826.o' '-o' '/tmp/6827.o' '/usr/bin/pkg-config' '--version' '/bin/tar' '--help' Reading available packages... Warning: The package list for 'hackage.haskell.org' is 52.1 days old. Run 'cabal update' to get the latest list of available packages. Choosing modular solver. Resolving dependencies... Ready to install glib-0.12.5.4 Waiting for install task to finish... Extracting /opt/cabal/packages/hackage.haskell.org/glib/0.12.5.4/glib-0.12.5.4.tar.gz to /tmp/glib-0.12.5.4-6826... Updating glib.cabal with the latest revision from the index. creating /tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist/setup creating /tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist creating /tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist/setup copy /tmp/glib-0.12.5.4-6826/glib-0.12.5.4/Setup.hs to /tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist/setup/setup.hs '/usr/bin/ghc' '--make' '-odir' '/tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist/setup' '-hidir' '/tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist/setup' '-i' '-i/tmp/glib-0.12.5.4-6826/glib-0.12.5.4' '-package-db' '/opt/cabal/package.conf.d' '-package-id' 'Cabal-1.22.1.1-98c5a01d59dd973fd7113dbb82e82560' '/tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist/setup/setup.hs' '-o' '/tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist/setup/setup' '-threaded' [1 of 2] Compiling SetupWrapper ( /tmp/glib-0.12.5.4-6826/glib-0.12.5.4/SetupWrapper.hs, /tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist/setup/SetupWrapper.o ) /tmp/glib-0.12.5.4-6826/glib-0.12.5.4/SetupWrapper.hs:118:28: Warning: In the use of `configCompiler' (imported from Distribution.Simple.Configure): Deprecated: "'configCompiler' is deprecated. Use 'configCompilerEx' instead." [2 of 2] Compiling Main ( /tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist/setup/setup.hs, /tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist/setup/Main.o ) Linking /tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist/setup/setup ... /tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist/setup/setup configure --verbose=2 --ghc --prefix=/opt/cabal --bindir=/opt/cabal/bin --libdir=/opt/cabal/lib --libsubdir=glib-0.12.5.4/ghc-7.6.3 --libexecdir=/opt/cabal/libexec --datadir=/opt/cabal/share --datasubdir=glib-0.12.5.4 --docdir=/opt/cabal/share/doc/glib-0.12.5.4 --htmldir=/opt/cabal/share/doc/glib-0.12.5.4/html --haddockdir=/opt/cabal/share/doc/glib-0.12.5.4/html --sysconfdir=/opt/cabal/etc --enable-library-profiling --enable-optimization=2 --global --package-db=/opt/cabal/package.conf.d --flags=closure_signals --dependency=utf8-string=utf8-string-0.3.8-51169ff3d90963aa54c0a13eee5c3a53 --dependency=containers=containers-0.5.0.0-e7e1a93d7945e93a00ce12660e9ff290 --dependency=base=base-4.6.0.1-220b875e77822b0e1bf50c8f35d37dff --disable-tests --exact-configuration --disable-benchmarks [1 of 2] Compiling Gtk2HsSetup ( Gtk2HsSetup.hs, dist/setup-wrapper/Gtk2HsSetup.o ) [2 of 2] Compiling Main ( SetupMain.hs, dist/setup-wrapper/Main.o ) Linking dist/setup-wrapper/setup ... unrecognized option `--sysconfdir=/opt/cabal/etc' unrecognized option `--dependency=utf8-string=utf8-string-0.3.8-51169ff3d90963aa54c0a13eee5c3a53' unrecognized option `--dependency=containers=containers-0.5.0.0-e7e1a93d7945e93a00ce12660e9ff290' unrecognized option `--dependency=base=base-4.6.0.1-220b875e77822b0e1bf50c8f35d37dff' unrecognized option `--exact-configuration' Failed to install glib-0.12.5.4 World file is already up to date. cabal: Error: some packages failed to install: glib-0.12.5.4 failed during the configure step. The exception was: ExitFailure 1 cwr at sixpence cabal $ =================================================================== Moving to the default version of glib, I then get: =================================================================== cwr at sixpence cabal $ cabal --verbose --global --package-db=/opt/cabal/package.conf.d install glib Reading available packages... Choosing modular solver. Resolving dependencies... Ready to install glib-0.13.1.0 Waiting for install task to finish... Extracting /opt/cabal/packages/hackage.haskell.org/glib/0.13.1.0/glib-0.13.1.0.tar.gz to /tmp/glib-0.13.1.0-3703... Updating glib.cabal with the latest revision from the index. creating /tmp/glib-0.13.1.0-3703/glib-0.13.1.0/dist/setup creating /tmp/glib-0.13.1.0-3703/glib-0.13.1.0/dist creating /tmp/glib-0.13.1.0-3703/glib-0.13.1.0/dist/setup Failed to install glib-0.13.1.0 World file is already up to date. cabal: Error: some packages failed to install: glib-0.13.1.0 failed during the configure step. The exception was: user error (The package 'glib' requires Cabal library version -any && >=1.18 but no suitable version is installed.) cwr at sixpence cabal $ cabal --version cabal-install version 1.18.0.2 using version 1.18.1.2 of the Cabal library cwr at sixpence cabal $ =================================================================== And moving to the default version of cabal, I get: =================================================================== cwr at sixpence cabal $ cabal --verbose --global --package-db=/opt/cabal/package.conf.d install glib '/opt/cabal/bin/alex' '--version' '/opt/cabal/bin/cpphs' '--version' '/usr/bin/gcc' '-dumpversion' '/opt/cabal/bin/haddock' '--version' '/opt/cabal/bin/happy' '--version' '/usr/bin/hpc' 'version' looking for tool hsc2hs near compiler in /usr/bin found hsc2hs in /usr/bin/hsc2hs '/usr/bin/hsc2hs' '--version' '/opt/cabal/bin/HsColour' '-version' '/usr/bin/ghc' '-c' '/tmp/4186.c' '-o' '/tmp/4186.o' '/usr/bin/ld' '-x' '-r' '/tmp/4186.o' '-o' '/tmp/4187.o' '/usr/bin/pkg-config' '--version' '/bin/tar' '--help' Reading available packages... Warning: The package list for 'hackage.haskell.org' is 51.4 days old. Run 'cabal update' to get the latest list of available packages. Choosing modular solver. Resolving dependencies... Ready to install glib-0.13.1.0 Waiting for install task to finish... Extracting /opt/cabal/packages/hackage.haskell.org/glib/0.13.1.0/glib-0.13.1.0.tar.gz to /tmp/glib-0.13.1.0-4186... Updating glib.cabal with the latest revision from the index. creating /tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist/setup creating /tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist creating /tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist/setup copy /tmp/glib-0.13.1.0-4186/glib-0.13.1.0/Setup.hs to /tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist/setup/setup.hs '/usr/bin/ghc' '--make' '-odir' '/tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist/setup' '-hidir' '/tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist/setup' '-i' '-i/tmp/glib-0.13.1.0-4186/glib-0.13.1.0' '-package-db' '/opt/cabal/package.conf.d' '-package-id' 'Cabal-1.22.1.1-98c5a01d59dd973fd7113dbb82e82560' '/tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist/setup/setup.hs' '-o' '/tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist/setup/setup' '-threaded' [1 of 2] Compiling SetupWrapper ( /tmp/glib-0.13.1.0-4186/glib-0.13.1.0/SetupWrapper.hs, /tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist/setup/SetupWrapper.o ) [2 of 2] Compiling Main ( /tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist/setup/setup.hs, /tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist/setup/Main.o ) Linking /tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist/setup/setup ... /tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist/setup/setup configure --verbose=2 --ghc --prefix=/opt/cabal --bindir=/opt/cabal/bin --libdir=/opt/cabal/lib --libsubdir=glib-0.13.1.0/ghc-7.6.3 --libexecdir=/opt/cabal/libexec --datadir=/opt/cabal/share --datasubdir=glib-0.13.1.0 --docdir=/opt/cabal/share/doc/glib-0.13.1.0 --htmldir=/opt/cabal/share/doc/glib-0.13.1.0/html --haddockdir=/opt/cabal/share/doc/glib-0.13.1.0/html --sysconfdir=/opt/cabal/etc --enable-library-profiling --enable-optimization=2 --global --package-db=/opt/cabal/package.conf.d --flags=closure_signals --dependency=utf8-string=utf8-string-0.3.8-51169ff3d90963aa54c0a13eee5c3a53 --dependency=text=text-1.1.1.3-3a54592a9f7d64cef4851163d5553453 --dependency=containers=containers-0.5.0.0-e7e1a93d7945e93a00ce12660e9ff290 --dependency=bytestring=bytestring-0.10.0.2-14ba8002009bf89cdad6038c30eda3fd --dependency=base=base-4.6.0.1-220b875e77822b0e1bf50c8f35d37dff --disable-tests --exact-configuration --disable-benchmarks [1 of 2] Compiling Gtk2HsSetup ( Gtk2HsSetup.hs, dist/setup-wrapper/Gtk2HsSetup.o ) Gtk2HsSetup.hs:167:16: Not in scope: `LBI.getComponentLocalBuildInfo' Failed to install glib-0.13.1.0 Updating world file... cabal: Error: some packages failed to install: glib-0.13.1.0 failed during the configure step. The exception was: ExitFailure 1 cwr at sixpence cabal $ =================================================================== Does anyone have any idea how to fix any or all of these errors? Thanks - Will From John.Oldman at delphi.com Wed May 6 16:30:11 2015 From: John.Oldman at delphi.com (Oldman, John) Date: Wed, 6 May 2015 16:30:11 +0000 Subject: [Haskell-beginners] unsubscribe Message-ID: <9038715DF9B6DC429E2CD9E1A9180B3E01AA66CE@017-CH1MPN4-093.017d.mgd.msft.net> unsubscribe **************************************************************************************** Note: If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. Thank you. **************************************************************************************** -------------- next part -------------- An HTML attachment was scrubbed... URL: From diewlq at gmail.com Wed May 6 23:14:59 2015 From: diewlq at gmail.com (Cameron P-B) Date: Wed, 6 May 2015 20:14:59 -0300 Subject: [Haskell-beginners] Missing C libraries on windows Message-ID: I'm not sure if this is the right place for this, but I've repeatedly run into issues when installing packages through cabal. It complains about missing C libraries and then explains that I can solve the problem by "installing the system package that provides this library". This has never worked for me and so I assume I'm not doing it correctly. For example, I am currently trying to install ftgl. Using --extra-include-dirs and --extra-lib-dirs to point at the lib and include of the c source folder of ftgl doesn't seem to work. Neither did putting the dll's in the path. The tutorial linked from the wiki:[ https://noamlewis.wordpress.com/2012/12/16/cabal-install-ftgl-on-windows-and-getting-exes-that-use-it-to-work/ ] also doesn't work for me. And so I was wondering if anyone has had more recent success with that library and more generally if there were any suggestions as to what I might be doing wrong. -------------- next part -------------- An HTML attachment was scrubbed... URL: From magnus at therning.org Thu May 7 05:54:59 2015 From: magnus at therning.org (Magnus Therning) Date: Thu, 7 May 2015 07:54:59 +0200 Subject: [Haskell-beginners] unsubscribe In-Reply-To: <9038715DF9B6DC429E2CD9E1A9180B3E01AA66CE@017-CH1MPN4-093.017d.mgd.msft.net> References: <9038715DF9B6DC429E2CD9E1A9180B3E01AA66CE@017-CH1MPN4-093.017d.mgd.msft.net> Message-ID: On 6 May 2015 at 18:30, Oldman, John wrote: > unsubscribe You'll have more luck unsubscribing if you go to http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners /M > **************************************************************************************** > Note: If the reader of this message is not the intended recipient, or an > employee or agent responsible for delivering this message to the intended > recipient, you are hereby notified that any dissemination, distribution or > copying of this communication is strictly prohibited. If you have received > this communication in error, please notify us immediately by replying to the > message and deleting it from your computer. Thank you. > **************************************************************************************** > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Magnus Therning OpenPGP: 0xAB4DFBA4 email: magnus at therning.org jabber: magnus at therning.org twitter: magthe http://therning.org/magnus From haskell at elisehuard.be Thu May 7 09:35:33 2015 From: haskell at elisehuard.be (Elise Huard) Date: Thu, 7 May 2015 11:35:33 +0200 Subject: [Haskell-beginners] Missing C libraries on windows In-Reply-To: References: Message-ID: Hi Cameron, which error message do you get? I've hacked my way through such issues by manually adding an extra-lib-dirs: with the _absolute_ path in the executable or library section of the cabal file, so that could be something to try. It's not a final solution obviously, but it would allow you to check whether it works at all. An example on github of this https://github.com/nikki-and-the-robots/nikki/blob/master/src/testsuite/testsuite.cabal#L99 Elise On 7 May 2015 at 01:14, Cameron P-B wrote: > I'm not sure if this is the right place for this, but I've repeatedly run > into issues when installing packages through cabal. It complains about > missing C libraries and then explains that I can solve the problem by > "installing the system package that provides this library". This has never > worked for me and so I assume I'm not doing it correctly. > > For example, I am currently trying to install ftgl. Using > --extra-include-dirs and --extra-lib-dirs to point at the lib and include of > the c source folder of ftgl doesn't seem to work. Neither did putting the > dll's in the path. > > The tutorial linked from the > wiki:[https://noamlewis.wordpress.com/2012/12/16/cabal-install-ftgl-on-windows-and-getting-exes-that-use-it-to-work/] > > also doesn't work for me. And so I was wondering if anyone has had more > recent success with that library and more generally if there were any > suggestions as to what I might be doing wrong. > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From haskell at elisehuard.be Thu May 7 09:37:02 2015 From: haskell at elisehuard.be (Elise Huard) Date: Thu, 7 May 2015 11:37:02 +0200 Subject: [Haskell-beginners] Missing C libraries on windows In-Reply-To: References: Message-ID: note that they also add extra-libraries: so that's also worth adding. On 7 May 2015 at 11:35, Elise Huard wrote: > Hi Cameron, > > which error message do you get? > I've hacked my way through such issues by manually adding an > extra-lib-dirs: > with the _absolute_ path in the executable or library section of the > cabal file, so that could be something to try. It's not a final > solution obviously, but it would allow you to check whether it works > at all. > An example on github of this > https://github.com/nikki-and-the-robots/nikki/blob/master/src/testsuite/testsuite.cabal#L99 > > Elise > > On 7 May 2015 at 01:14, Cameron P-B wrote: >> I'm not sure if this is the right place for this, but I've repeatedly run >> into issues when installing packages through cabal. It complains about >> missing C libraries and then explains that I can solve the problem by >> "installing the system package that provides this library". This has never >> worked for me and so I assume I'm not doing it correctly. >> >> For example, I am currently trying to install ftgl. Using >> --extra-include-dirs and --extra-lib-dirs to point at the lib and include of >> the c source folder of ftgl doesn't seem to work. Neither did putting the >> dll's in the path. >> >> The tutorial linked from the >> wiki:[https://noamlewis.wordpress.com/2012/12/16/cabal-install-ftgl-on-windows-and-getting-exes-that-use-it-to-work/] >> >> also doesn't work for me. And so I was wondering if anyone has had more >> recent success with that library and more generally if there were any >> suggestions as to what I might be doing wrong. >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> From magnus at therning.org Thu May 7 09:55:38 2015 From: magnus at therning.org (Magnus Therning) Date: Thu, 7 May 2015 11:55:38 +0200 Subject: [Haskell-beginners] Missing C libraries on windows In-Reply-To: References: Message-ID: On 7 May 2015 at 01:14, Cameron P-B wrote: > I'm not sure if this is the right place for this, but I've repeatedly run > into issues when installing packages through cabal. It complains about > missing C libraries and then explains that I can solve the problem by > "installing the system package that provides this library". This has never > worked for me and so I assume I'm not doing it correctly. > > For example, I am currently trying to install ftgl. Using > --extra-include-dirs and --extra-lib-dirs to point at the lib and include of > the c source folder of ftgl doesn't seem to work. Neither did putting the > dll's in the path. > > The tutorial linked from the > wiki:[https://noamlewis.wordpress.com/2012/12/16/cabal-install-ftgl-on-windows-and-getting-exes-that-use-it-to-work/] > > also doesn't work for me. And so I was wondering if anyone has had more > recent success with that library and more generally if there were any > suggestions as to what I might be doing wrong. One easy way out of it is to switch to using Linux (e.g. in a VM). That is, unless you absolutely have to use Windows. /M -- Magnus Therning OpenPGP: 0xAB4DFBA4 email: magnus at therning.org jabber: magnus at therning.org twitter: magthe http://therning.org/magnus From hjgtuyl at chello.nl Thu May 7 10:10:52 2015 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Thu, 07 May 2015 12:10:52 +0200 Subject: [Haskell-beginners] Missing C libraries on windows In-Reply-To: References: Message-ID: On Thu, 07 May 2015 01:14:59 +0200, Cameron P-B wrote: > I'm not sure if this is the right place for this, but I've repeatedly run > into issues when installing packages through cabal. It complains about > missing C libraries and then explains that I can solve the problem by > "installing the system package that provides this library". This has > never > worked for me and so I assume I'm not doing it correctly. I usually use commands like: Set LIBRARY_DIR=C:\Libs Set PATH=%LIBRARY_DIR%\bin;%PATH% Set LIBRARY_PATH=%LIBRARY_DIR%\lib Set C_INCLUDE_PATH=%LIBRARY_DIR%\include\SDL2;%LIBRARY_DIR%\include For C++ libraries you need to set CPLUS_INCLUDE_PATH as well. In general it is not advisable to copy DLLs to the Windows directory, this might result in incompatibility problems (if other applications use different versions of the DLLs); install the DLLs in the same directory as the executable. Regards, Henk-Jan van Tuyl -- Folding at home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming -- From diewlq at gmail.com Fri May 8 02:30:58 2015 From: diewlq at gmail.com (Cameron P-B) Date: Thu, 7 May 2015 23:30:58 -0300 Subject: [Haskell-beginners] Missing C libraries on windows Message-ID: Ok, thanks everyone, It all seems to be working now. Setting the environmental variables as suggested and generally following the steps here [https://wiki.haskell.org/SDL/Windows] appears to have been all that was needed; as well as a bit of trial and error as to what was meant by the development libraries. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan9131 at gmail.com Fri May 8 07:58:49 2015 From: dan9131 at gmail.com (Dananji Liyanage) Date: Fri, 8 May 2015 13:28:49 +0530 Subject: [Haskell-beginners] Uses of record syntax Message-ID: Hi All, I'm Dananji, a new comer to this language and functional programming as well. Can anyone please help me understand what is record syntax and its use? -- Regards, Dananji Liyanage -------------- next part -------------- An HTML attachment was scrubbed... URL: From grzegorzmilka at gmail.com Fri May 8 08:15:25 2015 From: grzegorzmilka at gmail.com (Grzegorz Milka) Date: Fri, 08 May 2015 10:15:25 +0200 Subject: [Haskell-beginners] Uses of record syntax In-Reply-To: References: Message-ID: <554C709D.5010300@gmail.com> Hi, You should start with openly accessible sources explaining it: http://en.wikibooks.org/wiki/Haskell/More_on_datatypes http://learnyouahaskell.com/making-our-own-types-and-typeclasses http://book.realworldhaskell.org/read/defining-types-streamlining-functions.html If you have more questions after reading those sources then feel free to ask. Best, Greg On 08.05.2015 09:58, Dananji Liyanage wrote: > Hi All, > > I'm Dananji, a new comer to this language and functional programming as > well. > > Can anyone please help me understand what is record syntax and its use? > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From dan9131 at gmail.com Fri May 8 08:34:54 2015 From: dan9131 at gmail.com (Dananji Liyanage) Date: Fri, 8 May 2015 14:04:54 +0530 Subject: [Haskell-beginners] Uses of record syntax In-Reply-To: <554C709D.5010300@gmail.com> References: <554C709D.5010300@gmail.com> Message-ID: Thank You :) On Fri, May 8, 2015 at 1:45 PM, Grzegorz Milka wrote: > Hi, > > You should start with openly accessible sources explaining it: > > http://en.wikibooks.org/wiki/Haskell/More_on_datatypes > > http://learnyouahaskell.com/making-our-own-types-and-typeclasses > > > http://book.realworldhaskell.org/read/defining-types-streamlining-functions.html > > If you have more questions after reading those sources then feel free to > ask. > > Best, > Greg > > On 08.05.2015 09:58, Dananji Liyanage wrote: > > Hi All, > > I'm Dananji, a new comer to this language and functional programming as > well. > > Can anyone please help me understand what is record syntax and its use? > > > > > _______________________________________________ > 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 > > -- Regards, Dananji Liyanage -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan9131 at gmail.com Fri May 8 08:54:33 2015 From: dan9131 at gmail.com (Dananji Liyanage) Date: Fri, 8 May 2015 14:24:33 +0530 Subject: [Haskell-beginners] Uses of record syntax In-Reply-To: References: <554C709D.5010300@gmail.com> Message-ID: ?Got it!! Thanks :) On Fri, May 8, 2015 at 2:04 PM, Dananji Liyanage wrote: > Thank You :) > > On Fri, May 8, 2015 at 1:45 PM, Grzegorz Milka > wrote: > >> Hi, >> >> You should start with openly accessible sources explaining it: >> >> http://en.wikibooks.org/wiki/Haskell/More_on_datatypes >> >> http://learnyouahaskell.com/making-our-own-types-and-typeclasses >> >> >> http://book.realworldhaskell.org/read/defining-types-streamlining-functions.html >> >> If you have more questions after reading those sources then feel free to >> ask. >> >> Best, >> Greg >> >> On 08.05.2015 09:58, Dananji Liyanage wrote: >> >> Hi All, >> >> I'm Dananji, a new comer to this language and functional programming as >> well. >> >> Can anyone please help me understand what is record syntax and its use? >> >> >> >> >> _______________________________________________ >> 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 >> >> > > > -- > Regards, > Dananji Liyanage > -- Regards, Dananji Liyanage -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan9131 at gmail.com Fri May 8 09:00:23 2015 From: dan9131 at gmail.com (Dananji Liyanage) Date: Fri, 8 May 2015 14:30:23 +0530 Subject: [Haskell-beginners] Creating modules Message-ID: Hi All, I'm following this lecture[1] series and stuck at the module creation section. Even though I understand the idea of the module I can't figure out the exact syntax to module creation. Do we have to compile the Haskell file containing the module declaration? For an example: Do I have to compile this; module metricCalc(.....) where ... in a file metricCalc.hs ?[1] http://shuklan.com/haskell/index.html -- Regards, Dananji Liyanage -------------- next part -------------- An HTML attachment was scrubbed... URL: From magnus at therning.org Fri May 8 10:43:38 2015 From: magnus at therning.org (Magnus Therning) Date: Fri, 8 May 2015 12:43:38 +0200 Subject: [Haskell-beginners] Creating modules In-Reply-To: References: Message-ID: On 8 May 2015 at 11:00, Dananji Liyanage wrote: > Hi All, > > I'm following this lecture[1] series and stuck at the module creation > section. > > Even though I understand the idea of the module I can't figure out the exact > syntax to module creation. > > Do we have to compile the Haskell file containing the module declaration? > > For an example: > > Do I have to compile this; > > module metricCalc(.....) where ... > in a file metricCalc.hs (First off, I believe module names must start with an uppercase letter, i.e. call it MetricCalc.) It depends on what you mean more exactly. You can use `ghci` to load the source file directly: ~~~ Prelude> :l MetricCalc.hs *MetricCalc> ~~~ If you use Cabal you can compile it and place it in a library which you subsequently can install, so that you can use it from other projects you work on. /M -- Magnus Therning OpenPGP: 0xAB4DFBA4 email: magnus at therning.org jabber: magnus at therning.org twitter: magthe http://therning.org/magnus From dan9131 at gmail.com Fri May 8 10:53:47 2015 From: dan9131 at gmail.com (Dananji Liyanage) Date: Fri, 8 May 2015 16:23:47 +0530 Subject: [Haskell-beginners] Creating modules In-Reply-To: References: Message-ID: ?Thanks Magnus!! Got it to working. On Fri, May 8, 2015 at 4:13 PM, Magnus Therning wrote: > On 8 May 2015 at 11:00, Dananji Liyanage wrote: > > Hi All, > > > > I'm following this lecture[1] series and stuck at the module creation > > section. > > > > Even though I understand the idea of the module I can't figure out the > exact > > syntax to module creation. > > > > Do we have to compile the Haskell file containing the module > declaration? > > > > For an example: > > > > Do I have to compile this; > > > > module metricCalc(.....) where ... > > in a file metricCalc.hs > > (First off, I believe module names must start with an uppercase > letter, i.e. call it MetricCalc.) > > It depends on what you mean more exactly. > > You can use `ghci` to load the source file directly: > > ~~~ > Prelude> :l MetricCalc.hs > *MetricCalc> > ~~~ > > If you use Cabal you can compile it and place it in a library which > you subsequently can install, so that you can use it from other > projects you work on. > > /M > > -- > Magnus Therning OpenPGP: 0xAB4DFBA4 > email: magnus at therning.org jabber: magnus at therning.org > twitter: magthe http://therning.org/magnus > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Regards, Dananji Liyanage -------------- next part -------------- An HTML attachment was scrubbed... URL: From magnus at therning.org Fri May 8 11:01:07 2015 From: magnus at therning.org (Magnus Therning) Date: Fri, 8 May 2015 13:01:07 +0200 Subject: [Haskell-beginners] Creating modules In-Reply-To: References: Message-ID: On 8 May 2015 at 12:53, Dananji Liyanage wrote: > Thanks Magnus!! > > Got it to working. Excellent! I can recommend reading the ghc docs[1], they are good and very readable. Then peruse Hackage to find examples of how things work. /M [1]: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/index.html -- Magnus Therning OpenPGP: 0xAB4DFBA4 email: magnus at therning.org jabber: magnus at therning.org twitter: magthe http://therning.org/magnus From dan9131 at gmail.com Fri May 8 11:05:06 2015 From: dan9131 at gmail.com (Dananji Liyanage) Date: Fri, 8 May 2015 16:35:06 +0530 Subject: [Haskell-beginners] Creating modules In-Reply-To: References: Message-ID: Thank you very much :) On Fri, May 8, 2015 at 4:31 PM, Magnus Therning wrote: > On 8 May 2015 at 12:53, Dananji Liyanage wrote: > > Thanks Magnus!! > > > > Got it to working. > > Excellent! I can recommend reading the ghc docs[1], they are good and > very readable. Then peruse Hackage to find examples of how things > work. > > /M > > [1]: > https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/index.html > > -- > Magnus Therning OpenPGP: 0xAB4DFBA4 > email: magnus at therning.org jabber: magnus at therning.org > twitter: magthe http://therning.org/magnus > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Regards, Dananji Liyanage -------------- next part -------------- An HTML attachment was scrubbed... URL: From christian.sperandio at gmail.com Fri May 8 13:30:56 2015 From: christian.sperandio at gmail.com (Christian Sperandio) Date: Fri, 8 May 2015 15:30:56 +0200 Subject: [Haskell-beginners] Implementation question about directed acyclic graph Message-ID: Hi, I?m learning the Bayesian networks and I want to write my own implementation. So, I started implementing t a DAG in Haskell but I?ve got some questions about the best way to do it in a functional mind. I?m thinking about a DAG implementation avoids duplicate information. So, I imagined this implementation: data Node a = Node { event :: a, proved :: Bool, nodeID :: Int } type Connections = M.Map Int [Int] data Graph a = Empty | Gragh { nodes :: M.Map Int (Node a), nextID :: Int, connections :: Connections } My idea is to yield an ID for each node and use this ID for connections. Thus, I can have the same events connected many times without duplicate the event data. And when I have to change a node state, I don?t need to search all occurrences in the graph. Am I on the right way ? Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From edwards.benj at gmail.com Fri May 8 14:02:30 2015 From: edwards.benj at gmail.com (Benjamin Edwards) Date: Fri, 08 May 2015 14:02:30 +0000 Subject: [Haskell-beginners] Implementation question about directed acyclic graph In-Reply-To: References: Message-ID: Having a look at how graphs are implemented in fgl might be helpful to you. Ben On Fri, 8 May 2015 at 14:31 Christian Sperandio < christian.sperandio at gmail.com> wrote: > Hi, > > I?m learning the Bayesian networks and I want to write my own > implementation. > So, I started implementing t a DAG in Haskell but I?ve got some questions > about the best way to do it in a functional mind. > > I?m thinking about a DAG implementation avoids duplicate information. So, > I imagined this implementation: > > data Node a = Node { event :: a, proved :: Bool, nodeID :: Int } > > type Connections = M.Map Int [Int] > > data Graph a = Empty > | Gragh { nodes :: M.Map Int (Node a), nextID :: Int, > connections :: Connections } > > > > My idea is to yield an ID for each node and use this ID for connections. > Thus, I can have the same events connected many times without duplicate the > event data. > And when I have to change a node state, I don?t need to search all > occurrences in the graph. > > Am I on the right way ? > > Chris > > _______________________________________________ > 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 rasen.dubi at gmail.com Fri May 8 15:47:24 2015 From: rasen.dubi at gmail.com (Alexey Shmalko) Date: Fri, 8 May 2015 18:47:24 +0300 Subject: [Haskell-beginners] Creating modules In-Reply-To: References: Message-ID: Just a quick note. When you compile (or load in ghci) your Main module, GHC is smart enough to find other modules it import without further help. So usually you won't care about compiling/recompiling distinct modules, only the whole program. On Fri, May 8, 2015 at 2:05 PM, Dananji Liyanage wrote: > Thank you very much :) > > On Fri, May 8, 2015 at 4:31 PM, Magnus Therning wrote: >> >> On 8 May 2015 at 12:53, Dananji Liyanage wrote: >> > Thanks Magnus!! >> > >> > Got it to working. >> >> Excellent! I can recommend reading the ghc docs[1], they are good and >> very readable. Then peruse Hackage to find examples of how things >> work. >> >> /M >> >> [1]: >> https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/index.html >> >> -- >> Magnus Therning OpenPGP: 0xAB4DFBA4 >> email: magnus at therning.org jabber: magnus at therning.org >> twitter: magthe http://therning.org/magnus >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > > -- > Regards, > Dananji Liyanage > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From shishir.srivastava at gmail.com Fri May 8 18:25:10 2015 From: shishir.srivastava at gmail.com (Shishir Srivastava) Date: Fri, 8 May 2015 19:25:10 +0100 Subject: [Haskell-beginners] Import issue Message-ID: Hi, I've imported the State monad module and used in the 'pop' function that will pop the head out of the list but am getting error in GHCi. ----- import Control.Monad.State let pop = State $ \(x:xs) -> (x,xs) :73:11: Not in scope: data constructor ?State? Perhaps you meant ?StateT? (imported from Control.Monad.State) ----- Please can anyone point out what the issue is here? Thanks, Shishir -------------- next part -------------- An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Fri May 8 18:36:53 2015 From: allbery.b at gmail.com (Brandon Allbery) Date: Fri, 8 May 2015 14:36:53 -0400 Subject: [Haskell-beginners] Import issue In-Reply-To: References: Message-ID: On Fri, May 8, 2015 at 2:25 PM, Shishir Srivastava < shishir.srivastava at gmail.com> wrote: > I've imported the State monad module and used in the 'pop' function that > will pop the head out of the list but am getting error in GHCi. > You are probably working from outdated documentation of some kind. The original standalone monads like State from mtl1 were replaced several years ago with type aliases (in this case `type State s a = StateT s Identity a`) in mtl2, which means State is no longer a constructor. The `state` function can be used as a quick replacement for the old `State` constructor for any purpose other than pattern matching. -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From doug at cs.dartmouth.edu Sat May 9 14:59:22 2015 From: doug at cs.dartmouth.edu (Doug McIlroy) Date: Sat, 09 May 2015 10:59:22 -0400 Subject: [Haskell-beginners] Implementation question about directed acyclic graph Message-ID: <201505091459.t49ExMq8008700@coolidge.cs.dartmouth.edu> Your suggested this representation > type Connections = M.Map Int a [Int] > > data Graph a = Empty > | Gragh { nodes :: M.Map Int (Node a), nextID :: Int, > connections :: Connections } Making connections by name (in this case an Int) entails table lookup at every step of any graph traversal. That is avoided by this simple representation: data Graph a = Graph a [Graph a] perhaps elaborated to allow the empty case data Graph a = Graph a [Graph a] | Empty If you need node identifiers, e.g. to recognize repeat visits to a node, they can be incorporated in data type a, or abstracted into another field data Eq id => Graph id a = Graph id a [Graph id a] Doug McIlroy From dan9131 at gmail.com Mon May 11 03:16:10 2015 From: dan9131 at gmail.com (Dananji Liyanage) Date: Mon, 11 May 2015 08:46:10 +0530 Subject: [Haskell-beginners] Creating modules In-Reply-To: References: Message-ID: Noted :) Thank you!! On Fri, May 8, 2015 at 9:17 PM, Alexey Shmalko wrote: > Just a quick note. When you compile (or load in ghci) your Main > module, GHC is smart enough to find other modules it import without > further help. So usually you won't care about compiling/recompiling > distinct modules, only the whole program. > > On Fri, May 8, 2015 at 2:05 PM, Dananji Liyanage > wrote: > > Thank you very much :) > > > > On Fri, May 8, 2015 at 4:31 PM, Magnus Therning > wrote: > >> > >> On 8 May 2015 at 12:53, Dananji Liyanage wrote: > >> > Thanks Magnus!! > >> > > >> > Got it to working. > >> > >> Excellent! I can recommend reading the ghc docs[1], they are good and > >> very readable. Then peruse Hackage to find examples of how things > >> work. > >> > >> /M > >> > >> [1]: > >> > https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/index.html > >> > >> -- > >> Magnus Therning OpenPGP: 0xAB4DFBA4 > >> email: magnus at therning.org jabber: magnus at therning.org > >> twitter: magthe http://therning.org/magnus > >> _______________________________________________ > >> Beginners mailing list > >> Beginners at haskell.org > >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > > > > > > > -- > > Regards, > > Dananji Liyanage > > > > _______________________________________________ > > 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 > -- Regards, Dananji Liyanage -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Mon May 11 15:44:04 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Mon, 11 May 2015 17:44:04 +0200 Subject: [Haskell-beginners] help to learn recursion Message-ID: <5550CE44.3030303@home.nl> I want to learn Haskell but still have some problems on using recursion. On simple tasks I can make it work but for example the tower of Hanoi I cannot figure out how things are can be solved. Is there a book or tutorial with exercises so I can pratice it? Roelof --- Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. http://www.avast.com From sumit.sahrawat.apm13 at iitbhu.ac.in Mon May 11 15:49:36 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Mon, 11 May 2015 21:19:36 +0530 Subject: [Haskell-beginners] help to learn recursion In-Reply-To: <5550CE44.3030303@home.nl> References: <5550CE44.3030303@home.nl> Message-ID: A good way to practice is to implement all functions that you know from Data.List. Most (all?) can be implemented using recursion, and then a subsequent excercise would be to refactor them using foldr, foldl etc. On 11 May 2015 at 21:14, Roelof Wobben wrote: > I want to learn Haskell but still have some problems on using recursion. > On simple tasks I can make it work but for example the tower of Hanoi I > cannot figure out how things are can be solved. > > Is there a book or tutorial with exercises so I can pratice it? > > Roelof > > > --- > Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. > http://www.avast.com > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From rasen.dubi at gmail.com Mon May 11 16:38:11 2015 From: rasen.dubi at gmail.com (Alexey Shmalko) Date: Mon, 11 May 2015 16:38:11 +0000 Subject: [Haskell-beginners] help to learn recursion In-Reply-To: <5550CE44.3030303@home.nl> References: <5550CE44.3030303@home.nl> Message-ID: You can try Haskell 99 problems [1]. At least first problems can help with getting recursion (I haven't worked through later, so I don't know about them). [1]: https://wiki.haskell.org/H-99:_Ninety-Nine_Haskell_Problems On Mon, May 11, 2015, 18:44 Roelof Wobben wrote: > I want to learn Haskell but still have some problems on using recursion. > On simple tasks I can make it work but for example the tower of Hanoi I > cannot figure out how things are can be solved. > > Is there a book or tutorial with exercises so I can pratice it? > > Roelof > > > --- > Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. > http://www.avast.com > > _______________________________________________ > 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 alex323 at gmail.com Tue May 12 02:11:04 2015 From: alex323 at gmail.com (Alex) Date: Mon, 11 May 2015 22:11:04 -0400 Subject: [Haskell-beginners] AMQP and nested exception handlers Message-ID: <20150511221104.7ae10c40@gmail.com> Hi: I am writing a small application which receives HTTP requests, translates them to JSON, and queues the requests using RabbitMQ. I am using exceptions to handle extreme cases, such as when a client's HTTP request lacks a critical header: lookupHeader :: RequestHeaders -> HeaderName -> Text lookupHeader hs h = decodeUtf8 $ fromMaybe notFound (lookup h hs) where notFound = throw $ MissingHeader $ decodeUtf8 $ original h The problem I am running in to is that the header isn't actually looked up until I call the AMQP library's publishMsg function. If I purposely do not supply a critical header, I get the following error printed to the screen: ConnectionClosedException "ConnectionClosedException \"UNEXPECTED_FRAME - expected content header for class 60, got non content header frame instead\"" If I add the following line just above the publishMsg function (to force evaluation), my exception handler is called successfully: print $ encode req As a result, I suspect that this is due to the fact that the "throw MissingHeader" is getting captured by the AMQP library. What's the best way to deal with this situation? -- Alex From dan9131 at gmail.com Tue May 12 03:47:16 2015 From: dan9131 at gmail.com (Dananji Liyanage) Date: Tue, 12 May 2015 09:17:16 +0530 Subject: [Haskell-beginners] Reading, Processing, and Writing I/O Message-ID: Hi All, As a newcomer to Haskell, I'm following a tutorial to learn I/O in Haskell. As an exercise I'm writing a small code to read from an input text file and process it and then write it back to an output file. The problem is that, it doesn't write to the output file after the input is being processed. Here's my code: module Main where import System.IO main = do input <- readFile "input.txt" let reversedInput = reverseInput (convert input) writeFile "reversed.txt" (reversedInput) -- These two lines are not printed on the shell putStrLn (show reversedInput) putStrLn "Writing to file...." -- Reversing the input reverseInput input = (last input) : reverseInput (init input) -- Convert from String IO -> String convert x = show (x) -- Regards, Dananji Liyanage -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Tue May 12 05:12:35 2015 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Tue, 12 May 2015 12:12:35 +0700 Subject: [Haskell-beginners] Reading, Processing, and Writing I/O In-Reply-To: References: Message-ID: On Tue, May 12, 2015 at 10:47 AM, Dananji Liyanage wrote: reverseInput input = (last input) : reverseInput (init input) This won't terminate. That's the bug. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From k-bx at k-bx.com Tue May 12 05:15:28 2015 From: k-bx at k-bx.com (Kostiantyn Rybnikov) Date: Tue, 12 May 2015 08:15:28 +0300 Subject: [Haskell-beginners] AMQP and nested exception handlers In-Reply-To: <20150511221104.7ae10c40@gmail.com> References: <20150511221104.7ae10c40@gmail.com> Message-ID: Hi. I would suggest to separate data-extraction from request stage and data-sending one. Create a data-structure that will represent a thing you will want to send into RabbitMQ, and build it before you send anything. Then catch exceptions in IO-based layer to handle exception case. This way you won't need any evaluation tricks and will get all exceptions during that phase. Cheers. 12 ????. 2015 05:11 "Alex" ????: > Hi: > > I am writing a small application which receives HTTP requests, > translates them to JSON, and queues the requests using RabbitMQ. > > I am using exceptions to handle extreme cases, such as when a client's > HTTP request lacks a critical header: > > lookupHeader :: RequestHeaders -> HeaderName -> Text > lookupHeader hs h = decodeUtf8 $ fromMaybe notFound > (lookup h hs) > where > notFound = throw $ MissingHeader $ decodeUtf8 $ original h > > The problem I am running in to is that the header isn't actually looked > up until I call the AMQP library's publishMsg function. If I purposely > do not supply a critical header, I get the following error printed to > the screen: > > ConnectionClosedException "ConnectionClosedException \"UNEXPECTED_FRAME > - expected content header for class 60, got non content header frame > instead\"" > > If I add the following line just above the publishMsg function (to > force evaluation), my exception handler is called successfully: > > print $ encode req > > As a result, I suspect that this is due to the fact that the "throw > MissingHeader" is getting captured by the AMQP library. What's the best > way to deal with this situation? > > -- > Alex > _______________________________________________ > 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 dan9131 at gmail.com Tue May 12 05:16:27 2015 From: dan9131 at gmail.com (Dananji Liyanage) Date: Tue, 12 May 2015 10:46:27 +0530 Subject: [Haskell-beginners] Reading, Processing, and Writing I/O In-Reply-To: References: Message-ID: Thank you :) On Tue, May 12, 2015 at 10:42 AM, Kim-Ee Yeoh wrote: > > On Tue, May 12, 2015 at 10:47 AM, Dananji Liyanage > wrote: > > reverseInput input = (last input) : reverseInput (init input) > > > This won't terminate. That's the bug. > > -- Kim-Ee > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Regards, Dananji Liyanage -------------- next part -------------- An HTML attachment was scrubbed... URL: From alex323 at gmail.com Tue May 12 05:23:22 2015 From: alex323 at gmail.com (Alex) Date: Tue, 12 May 2015 01:23:22 -0400 Subject: [Haskell-beginners] AMQP and nested exception handlers In-Reply-To: References: <20150511221104.7ae10c40@gmail.com> Message-ID: <20150512012322.51cfd61f@gmail.com> On Tue, 12 May 2015 08:15:28 +0300 Kostiantyn Rybnikov wrote: > Hi. > > I would suggest to separate data-extraction from request stage and > data-sending one. Create a data-structure that will represent a thing > you will want to send into RabbitMQ, and build it before you send > anything. Then catch exceptions in IO-based layer to handle exception > case. > > This way you won't need any evaluation tricks and will get all > exceptions during that phase. > In my case, the HTTP request is immediately parsed and a data structure representing the request is created. The request is forwarded to the AMQP code which does the following: publishMsg chan "" "the-queue" newMsg { msgDeliveryMode = Just Persistent , msgReplyTo = Just cbQueue , msgBody = encode req } where "encode req" uses aeson to transform the data structure in to JSON. I tried to make the values which comprise the request data structure strict (by prefixing them with `!'), but it does not seem to help. > Cheers. > 12 ????. 2015 05:11 "Alex" ????: > > > Hi: > > > > I am writing a small application which receives HTTP requests, > > translates them to JSON, and queues the requests using RabbitMQ. > > > > I am using exceptions to handle extreme cases, such as when a > > client's HTTP request lacks a critical header: > > > > lookupHeader :: RequestHeaders -> HeaderName -> Text > > lookupHeader hs h = decodeUtf8 $ fromMaybe notFound > > (lookup h hs) > > where > > notFound = throw $ MissingHeader $ decodeUtf8 $ original h > > > > The problem I am running in to is that the header isn't actually > > looked up until I call the AMQP library's publishMsg function. If I > > purposely do not supply a critical header, I get the following > > error printed to the screen: > > > > ConnectionClosedException "ConnectionClosedException > > \"UNEXPECTED_FRAME > > - expected content header for class 60, got non content header frame > > instead\"" > > > > If I add the following line just above the publishMsg function (to > > force evaluation), my exception handler is called successfully: > > > > print $ encode req > > > > As a result, I suspect that this is due to the fact that the "throw > > MissingHeader" is getting captured by the AMQP library. What's the > > best way to deal with this situation? > > > > -- > > Alex > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Alex From rasen.dubi at gmail.com Tue May 12 05:24:32 2015 From: rasen.dubi at gmail.com (Alexey Shmalko) Date: Tue, 12 May 2015 05:24:32 +0000 Subject: [Haskell-beginners] AMQP and nested exception handlers In-Reply-To: <20150511221104.7ae10c40@gmail.com> References: <20150511221104.7ae10c40@gmail.com> Message-ID: Your issue is related to Lazy evaluation. Your function (lookupHeader) isn't actually evaluated before you call publishMsg or print. You need to put seq or deepseq to overcome this, or put your exception handler in place when your function is actually evaluated. Unfortunately, you haven't provided the calling code, so I have no specific suggestion. Just read some info on Lazy vs. Strict. Parallel and Concurrent Programming in Haskell Chapter 2 [1] has a good description (just skip "The Eval Monad, rpar, and rseq" section and continue with deepseq). Here is a good chapter on exception [2], if you need one. [1]: http://chimera.labs.oreilly.com/books/1230000000929/ch02.html [2]: http://chimera.labs.oreilly.com/books/1230000000929/ch08.html#sec_exceptions On Tue, May 12, 2015 at 5:11 AM Alex wrote: > Hi: > > I am writing a small application which receives HTTP requests, > translates them to JSON, and queues the requests using RabbitMQ. > > I am using exceptions to handle extreme cases, such as when a client's > HTTP request lacks a critical header: > > lookupHeader :: RequestHeaders -> HeaderName -> Text > lookupHeader hs h = decodeUtf8 $ fromMaybe notFound > (lookup h hs) > where > notFound = throw $ MissingHeader $ decodeUtf8 $ original h > > The problem I am running in to is that the header isn't actually looked > up until I call the AMQP library's publishMsg function. If I purposely > do not supply a critical header, I get the following error printed to > the screen: > > ConnectionClosedException "ConnectionClosedException \"UNEXPECTED_FRAME > - expected content header for class 60, got non content header frame > instead\"" > > If I add the following line just above the publishMsg function (to > force evaluation), my exception handler is called successfully: > > print $ encode req > > As a result, I suspect that this is due to the fact that the "throw > MissingHeader" is getting captured by the AMQP library. What's the best > way to deal with this situation? > > -- > Alex > _______________________________________________ > 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 alex323 at gmail.com Tue May 12 06:10:50 2015 From: alex323 at gmail.com (Alex) Date: Tue, 12 May 2015 02:10:50 -0400 Subject: [Haskell-beginners] AMQP and nested exception handlers In-Reply-To: References: <20150511221104.7ae10c40@gmail.com> Message-ID: <20150512021050.24aebc09@gmail.com> On Tue, 12 May 2015 05:24:32 +0000 Alexey Shmalko wrote: > Your issue is related to Lazy evaluation. Your function (lookupHeader) > isn't actually evaluated before you call publishMsg or print. You > need to put seq or deepseq to overcome this, or put your exception > handler in place when your function is actually evaluated. > Unfortunately, you haven't provided the calling code, so I have no > specific suggestion. Just read some info on Lazy vs. Strict. > Per your suggestion, I tried out deepseq, and it doesn't seem to be working. Below is the code which sends the message to RMQ. As you've noted, `req' is not fully evaluated at this point: publishMsg chan "" "the-queue" newMsg { msgDeliveryMode = Just Persistent , msgReplyTo = Just cbQueue , msgBody = encode req } If I put this line above publishMsg, the problem still exists: _ <- return $!! req This is counter intuitive, because I would have thought that running deepseq on req would fully evaluate it to NF, but that doesn't seem to be the case. > Parallel and Concurrent Programming in Haskell Chapter 2 [1] has a > good description (just skip "The Eval Monad, rpar, and rseq" section > and continue with deepseq). > Here is a good chapter on exception [2], if you need one. > > [1]: http://chimera.labs.oreilly.com/books/1230000000929/ch02.html > [2]: > http://chimera.labs.oreilly.com/books/1230000000929/ch08.html#sec_exceptions > > On Tue, May 12, 2015 at 5:11 AM Alex wrote: > > > Hi: > > > > I am writing a small application which receives HTTP requests, > > translates them to JSON, and queues the requests using RabbitMQ. > > > > I am using exceptions to handle extreme cases, such as when a > > client's HTTP request lacks a critical header: > > > > lookupHeader :: RequestHeaders -> HeaderName -> Text > > lookupHeader hs h = decodeUtf8 $ fromMaybe notFound > > (lookup h hs) > > where > > notFound = throw $ MissingHeader $ decodeUtf8 $ original h > > > > The problem I am running in to is that the header isn't actually > > looked up until I call the AMQP library's publishMsg function. If I > > purposely do not supply a critical header, I get the following > > error printed to the screen: > > > > ConnectionClosedException "ConnectionClosedException > > \"UNEXPECTED_FRAME > > - expected content header for class 60, got non content header frame > > instead\"" > > > > If I add the following line just above the publishMsg function (to > > force evaluation), my exception handler is called successfully: > > > > print $ encode req > > > > As a result, I suspect that this is due to the fact that the "throw > > MissingHeader" is getting captured by the AMQP library. What's the > > best way to deal with this situation? > > > > -- > > Alex > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Alex From rasen.dubi at gmail.com Tue May 12 06:25:44 2015 From: rasen.dubi at gmail.com (Alexey Shmalko) Date: Tue, 12 May 2015 06:25:44 +0000 Subject: [Haskell-beginners] AMQP and nested exception handlers In-Reply-To: <20150512021050.24aebc09@gmail.com> References: <20150511221104.7ae10c40@gmail.com> <20150512021050.24aebc09@gmail.com> Message-ID: Seems, that you're putting it in the wrong place. Please, publish your code to lpaste [1]. Hmm.... Maybe you need evaluate `encode req`? On Tue, May 12, 2015 at 9:10 AM Alex wrote: > On Tue, 12 May 2015 05:24:32 +0000 > Alexey Shmalko wrote: > > > Your issue is related to Lazy evaluation. Your function (lookupHeader) > > isn't actually evaluated before you call publishMsg or print. You > > need to put seq or deepseq to overcome this, or put your exception > > handler in place when your function is actually evaluated. > > Unfortunately, you haven't provided the calling code, so I have no > > specific suggestion. Just read some info on Lazy vs. Strict. > > > > Per your suggestion, I tried out deepseq, and it doesn't seem to be > working. Below is the code which sends the message to RMQ. As you've > noted, `req' is not fully evaluated at this point: > > publishMsg chan "" "the-queue" > newMsg { msgDeliveryMode = Just Persistent > , msgReplyTo = Just cbQueue > , msgBody = encode req > } > > If I put this line above publishMsg, the problem still exists: > > _ <- return $!! req > > This is counter intuitive, because I would have thought that running > deepseq on req would fully evaluate it to NF, but that doesn't seem to > be the case. > > > Parallel and Concurrent Programming in Haskell Chapter 2 [1] has a > > good description (just skip "The Eval Monad, rpar, and rseq" section > > and continue with deepseq). > > Here is a good chapter on exception [2], if you need one. > > > > [1]: http://chimera.labs.oreilly.com/books/1230000000929/ch02.html > > [2]: > > > http://chimera.labs.oreilly.com/books/1230000000929/ch08.html#sec_exceptions > > > > On Tue, May 12, 2015 at 5:11 AM Alex wrote: > > > > > Hi: > > > > > > I am writing a small application which receives HTTP requests, > > > translates them to JSON, and queues the requests using RabbitMQ. > > > > > > I am using exceptions to handle extreme cases, such as when a > > > client's HTTP request lacks a critical header: > > > > > > lookupHeader :: RequestHeaders -> HeaderName -> Text > > > lookupHeader hs h = decodeUtf8 $ fromMaybe notFound > > > (lookup h hs) > > > where > > > notFound = throw $ MissingHeader $ decodeUtf8 $ original h > > > > > > The problem I am running in to is that the header isn't actually > > > looked up until I call the AMQP library's publishMsg function. If I > > > purposely do not supply a critical header, I get the following > > > error printed to the screen: > > > > > > ConnectionClosedException "ConnectionClosedException > > > \"UNEXPECTED_FRAME > > > - expected content header for class 60, got non content header frame > > > instead\"" > > > > > > If I add the following line just above the publishMsg function (to > > > force evaluation), my exception handler is called successfully: > > > > > > print $ encode req > > > > > > As a result, I suspect that this is due to the fact that the "throw > > > MissingHeader" is getting captured by the AMQP library. What's the > > > best way to deal with this situation? > > > > > > -- > > > Alex > > > _______________________________________________ > > > Beginners mailing list > > > Beginners at haskell.org > > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > > > > -- > Alex > -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Tue May 12 06:32:57 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Tue, 12 May 2015 08:32:57 +0200 Subject: [Haskell-beginners] why is this type wrong Message-ID: <55519E99.606@home.nl> An HTML attachment was scrubbed... URL: From rasen.dubi at gmail.com Tue May 12 06:37:08 2015 From: rasen.dubi at gmail.com (Alexey Shmalko) Date: Tue, 12 May 2015 06:37:08 +0000 Subject: [Haskell-beginners] why is this type wrong In-Reply-To: <55519E99.606@home.nl> References: <55519E99.606@home.nl> Message-ID: It's because first branch of last' returns a list instead of element. last' [] = [] The actual type is last' :: [a] -> [a] On Tue, May 12, 2015 at 9:33 AM Roelof Wobben wrote: > Hello, > > To practice recursion I try to make some functions of Data list myself on > the recursive way. > > First I will try last. > > So I did this : > > -- | Main entry point to the application. > module Main where > > -- | The main entry point. > last' :: [a] -> a > last' [] = [] > last' (x:xs) = last xs > > > but now I see this error message : > > src/Main.hs at 6:12-6:14 > Couldn't match expected type > a > with actual type > [t0] > a > is a rigid type variable bound by the type signature for last' :: [a] -> > a at > /home/app/isolation-runner-work/projects/112712/session.207/src/src/Main.hs:5:10 > Relevant bindings include last' :: [a] -> a (bound at > /home/app/isolation-runner-work/projects/112712/session.207/src/src/Main.hs:6:1) > ? > > I my oponion I have said that the input is a array and the output a > string, > > Roelof > > > > > ------------------------------ > [image: Avast logo] > > Dit e-mailbericht is gecontroleerd op virussen met Avast > antivirussoftware. > www.avast.com > > _______________________________________________ > 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 mwm at mired.org Tue May 12 06:39:37 2015 From: mwm at mired.org (Mike Meyer) Date: Tue, 12 May 2015 01:39:37 -0500 Subject: [Haskell-beginners] why is this type wrong In-Reply-To: <55519E99.606@home.nl> References: <55519E99.606@home.nl> Message-ID: On May 12, 2015 1:32 AM, "Roelof Wobben" wrote: > > Hello, > > To practice recursion I try to make some functions of Data list myself on the recursive way. > > First I will try last. > > So I did this : > > -- | Main entry point to the application. > module Main where > > -- | The main entry point. > last' :: [a] -> a > last' [] = [] > last' (x:xs) = last xs > > > but now I see this error message : > > src/Main.hs at 6:12-6:14 > Couldn't match expected type > a > with actual type > [t0] > a > is a rigid type variable bound by the type signature for last' :: [a] -> a at /home/app/isolation-runner-work/projects/112712/session.207/src/src/Main.hs:5:10 Relevant bindings include last' :: [a] -> a (bound at /home/app/isolation-runner-work/projects/112712/session.207/src/src/Main.hs:6:1) ? > > I my oponion I have said that the input is a array and the output a string, Except for saying list instead of array, I'd agree with that. But when you write last' [] = [], the output is [], which does not have the expected type of strong. So the actual type is a list. You need to return a string. -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Tue May 12 06:42:32 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Tue, 12 May 2015 08:42:32 +0200 Subject: [Haskell-beginners] why is this type wrong In-Reply-To: References: <55519E99.606@home.nl> Message-ID: <5551A0D8.7070908@home.nl> An HTML attachment was scrubbed... URL: From rasen.dubi at gmail.com Tue May 12 06:46:27 2015 From: rasen.dubi at gmail.com (Alexey Shmalko) Date: Tue, 12 May 2015 06:46:27 +0000 Subject: [Haskell-beginners] why is this type wrong In-Reply-To: <5551A0D8.7070908@home.nl> References: <55519E99.606@home.nl> <5551A0D8.7070908@home.nl> Message-ID: last' [] = error "last' on empty list" Otherwise, you should wrap the result in Maybe to make your function work as safeLast. Oh... GHC's exception seems to say you haven't defined `main` in your module. On Tue, May 12, 2015 at 9:42 AM Roelof Wobben wrote: > Mike Meyer schreef op 12-5-2015 om 8:39: > > On May 12, 2015 1:32 AM, "Roelof Wobben" wrote: > > > > Hello, > > > > To practice recursion I try to make some functions of Data list myself > on the recursive way. > > > > First I will try last. > > > > So I did this : > > > > -- | Main entry point to the application. > > module Main where > > > > -- | The main entry point. > > last' :: [a] -> a > > last' [] = [] > > last' (x:xs) = last xs > > > > > > but now I see this error message : > > > > src/Main.hs at 6:12-6:14 > > Couldn't match expected type > > a > > with actual type > > [t0] > > a > > is a rigid type variable bound by the type signature for last' :: [a] -> > a at > /home/app/isolation-runner-work/projects/112712/session.207/src/src/Main.hs:5:10 > Relevant bindings include last' :: [a] -> a (bound at > /home/app/isolation-runner-work/projects/112712/session.207/src/src/Main.hs:6:1) > ? > > > > I my oponion I have said that the input is a array and the output a > string, > > Except for saying list instead of array, I'd agree with that. But when you > write last' [] = [], the output is [], which does not have the expected > type of strong. So the actual type is a list. > > You need to return a string. > > > _______________________________________________ > Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > Thanks, > > I did change it to this : > > -- | Main entry point to the application. > module Main where > > -- | The main entry point. > last' :: [a] -> a > last' [x] = x > last' (x:xs) = last xs > > So I have to look at another way to say if there is a empty list then > there is no answer. > And when I run it i see this error message : > > GHC threw an exception : Not in scope: ?Main.main? > > > Roelof > > > > ------------------------------ > [image: Avast logo] > > Dit e-mailbericht is gecontroleerd op virussen met Avast > antivirussoftware. > www.avast.com > > _______________________________________________ > 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 sumit.sahrawat.apm13 at iitbhu.ac.in Tue May 12 06:47:21 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Tue, 12 May 2015 12:17:21 +0530 Subject: [Haskell-beginners] why is this type wrong In-Reply-To: References: <55519E99.606@home.nl> Message-ID: I recommending first trying out the `last' function in ghci. Prelude> last [] *** Exception: Prelude.last: empty list Prelude> last [1,2] 2 Instead of using last [] = [] You can use last [] = error "Empty list" Where error is defined in a way such that it can take on any type. In ghci Prelude> :type error error :: [Char] -> a On 12 May 2015 at 12:09, Mike Meyer wrote: > On May 12, 2015 1:32 AM, "Roelof Wobben" wrote: > > > > Hello, > > > > To practice recursion I try to make some functions of Data list myself > on the recursive way. > > > > First I will try last. > > > > So I did this : > > > > -- | Main entry point to the application. > > module Main where > > > > -- | The main entry point. > > last' :: [a] -> a > > last' [] = [] > > last' (x:xs) = last xs > > > > > > but now I see this error message : > > > > src/Main.hs at 6:12-6:14 > > Couldn't match expected type > > a > > with actual type > > [t0] > > a > > is a rigid type variable bound by the type signature for last' :: [a] -> > a at > /home/app/isolation-runner-work/projects/112712/session.207/src/src/Main.hs:5:10 > Relevant bindings include last' :: [a] -> a (bound at > /home/app/isolation-runner-work/projects/112712/session.207/src/src/Main.hs:6:1) > ? > > > > I my oponion I have said that the input is a array and the output a > string, > > Except for saying list instead of array, I'd agree with that. But when you > write last' [] = [], the output is [], which does not have the expected > type of strong. So the actual type is a list. > > You need to return a string. > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Tue May 12 06:48:29 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Tue, 12 May 2015 08:48:29 +0200 Subject: [Haskell-beginners] why is this type wrong In-Reply-To: References: <55519E99.606@home.nl> <5551A0D8.7070908@home.nl> Message-ID: <5551A23D.2060504@home.nl> An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Tue May 12 06:51:01 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Tue, 12 May 2015 12:21:01 +0530 Subject: [Haskell-beginners] why is this type wrong In-Reply-To: <5551A23D.2060504@home.nl> References: <55519E99.606@home.nl> <5551A0D8.7070908@home.nl> <5551A23D.2060504@home.nl> Message-ID: Make a dummy main function, main = return () And load this file in ghci to use you definition of last. The other option is to not make this module the Main module. Then also, you can load it in ghci. On 12 May 2015 at 12:18, Roelof Wobben wrote: > Thanks > > Can I just say Main = > I will google to look how to make a safeLast. > > Roelof > > > > Alexey Shmalko schreef op 12-5-2015 om 8:46: > > last' [] = error "last' on empty list" > > Otherwise, you should wrap the result in Maybe to make your function work > as safeLast. > > Oh... GHC's exception seems to say you haven't defined `main` in your > module. > > On Tue, May 12, 2015 at 9:42 AM Roelof Wobben wrote: > >> Mike Meyer schreef op 12-5-2015 om 8:39: >> >> On May 12, 2015 1:32 AM, "Roelof Wobben" wrote: >> > >> > Hello, >> > >> > To practice recursion I try to make some functions of Data list myself >> on the recursive way. >> > >> > First I will try last. >> > >> > So I did this : >> > >> > -- | Main entry point to the application. >> > module Main where >> > >> > -- | The main entry point. >> > last' :: [a] -> a >> > last' [] = [] >> > last' (x:xs) = last xs >> > >> > >> > but now I see this error message : >> > >> > src/Main.hs at 6:12-6:14 >> > Couldn't match expected type >> > a >> > with actual type >> > [t0] >> > a >> > is a rigid type variable bound by the type signature for last' :: [a] >> -> a at >> /home/app/isolation-runner-work/projects/112712/session.207/src/src/Main.hs:5:10 >> Relevant bindings include last' :: [a] -> a (bound at >> /home/app/isolation-runner-work/projects/112712/session.207/src/src/Main.hs:6:1) >> ? >> > >> > I my oponion I have said that the input is a array and the output a >> string, >> >> Except for saying list instead of array, I'd agree with that. But when >> you write last' [] = [], the output is [], which does not have the expected >> type of strong. So the actual type is a list. >> >> You need to return a string. >> >> >> _______________________________________________ >> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> >> Thanks, >> >> I did change it to this : >> >> -- | Main entry point to the application. >> module Main where >> >> -- | The main entry point. >> last' :: [a] -> a >> last' [x] = x >> last' (x:xs) = last xs >> >> So I have to look at another way to say if there is a empty list then >> there is no answer. >> And when I run it i see this error message : >> >> GHC threw an exception : Not in scope: ?Main.main? >> >> >> Roelof >> >> >> >> ------------------------------ >> [image: Avast logo] >> >> Dit e-mailbericht is gecontroleerd op virussen met Avast >> antivirussoftware. >> www.avast.com >> >> _______________________________________________ >> 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 > > > > > ------------------------------ > [image: Avast logo] > > Dit e-mailbericht is gecontroleerd op virussen met Avast > antivirussoftware. > www.avast.com > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From rasen.dubi at gmail.com Tue May 12 06:51:29 2015 From: rasen.dubi at gmail.com (Alexey Shmalko) Date: Tue, 12 May 2015 06:51:29 +0000 Subject: [Haskell-beginners] why is this type wrong In-Reply-To: <5551A23D.2060504@home.nl> References: <55519E99.606@home.nl> <5551A0D8.7070908@home.nl> <5551A23D.2060504@home.nl> Message-ID: I believe, you don't need main at all. Just load your source with ghci and call your functions from there. On Tue, May 12, 2015 at 9:48 AM Roelof Wobben wrote: > Thanks > > Can I just say Main = > I will google to look how to make a safeLast. > > Roelof > > > > Alexey Shmalko schreef op 12-5-2015 om 8:46: > > last' [] = error "last' on empty list" > > Otherwise, you should wrap the result in Maybe to make your function work > as safeLast. > > Oh... GHC's exception seems to say you haven't defined `main` in your > module. > > On Tue, May 12, 2015 at 9:42 AM Roelof Wobben wrote: > >> Mike Meyer schreef op 12-5-2015 om 8:39: >> >> On May 12, 2015 1:32 AM, "Roelof Wobben" wrote: >> > >> > Hello, >> > >> > To practice recursion I try to make some functions of Data list myself >> on the recursive way. >> > >> > First I will try last. >> > >> > So I did this : >> > >> > -- | Main entry point to the application. >> > module Main where >> > >> > -- | The main entry point. >> > last' :: [a] -> a >> > last' [] = [] >> > last' (x:xs) = last xs >> > >> > >> > but now I see this error message : >> > >> > src/Main.hs at 6:12-6:14 >> > Couldn't match expected type >> > a >> > with actual type >> > [t0] >> > a >> > is a rigid type variable bound by the type signature for last' :: [a] >> -> a at >> /home/app/isolation-runner-work/projects/112712/session.207/src/src/Main.hs:5:10 >> Relevant bindings include last' :: [a] -> a (bound at >> /home/app/isolation-runner-work/projects/112712/session.207/src/src/Main.hs:6:1) >> ? >> > >> > I my oponion I have said that the input is a array and the output a >> string, >> >> Except for saying list instead of array, I'd agree with that. But when >> you write last' [] = [], the output is [], which does not have the expected >> type of strong. So the actual type is a list. >> >> You need to return a string. >> >> >> _______________________________________________ >> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> >> Thanks, >> >> I did change it to this : >> >> -- | Main entry point to the application. >> module Main where >> >> -- | The main entry point. >> last' :: [a] -> a >> last' [x] = x >> last' (x:xs) = last xs >> >> So I have to look at another way to say if there is a empty list then >> there is no answer. >> And when I run it i see this error message : >> >> GHC threw an exception : Not in scope: ?Main.main? >> >> >> Roelof >> >> >> >> ------------------------------ >> [image: Avast logo] >> >> Dit e-mailbericht is gecontroleerd op virussen met Avast >> antivirussoftware. >> www.avast.com >> >> _______________________________________________ >> 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 > > > > > ------------------------------ > [image: Avast logo] > > Dit e-mailbericht is gecontroleerd op virussen met Avast > antivirussoftware. > www.avast.com > > _______________________________________________ > 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 alex323 at gmail.com Tue May 12 07:43:49 2015 From: alex323 at gmail.com (Alex) Date: Tue, 12 May 2015 03:43:49 -0400 Subject: [Haskell-beginners] AMQP and nested exception handlers In-Reply-To: References: <20150511221104.7ae10c40@gmail.com> <20150512021050.24aebc09@gmail.com> Message-ID: <20150512034349.7ce79bd4@gmail.com> On Tue, 12 May 2015 06:25:44 +0000 Alexey Shmalko wrote: > Seems, that you're putting it in the wrong place. Please, publish > your code to lpaste [1]. > > Hmm.... Maybe you need evaluate `encode req`? > I've created a test case demonstrating the behavior which is confusing me: http://lpaste.net/132446 -- Alex From rasen.dubi at gmail.com Tue May 12 08:32:08 2015 From: rasen.dubi at gmail.com (Alexey Shmalko) Date: Tue, 12 May 2015 08:32:08 +0000 Subject: [Haskell-beginners] AMQP and nested exception handlers In-Reply-To: <20150512034349.7ce79bd4@gmail.com> References: <20150511221104.7ae10c40@gmail.com> <20150512021050.24aebc09@gmail.com> <20150512034349.7ce79bd4@gmail.com> Message-ID: Seems you lack the proper instance of NFData for Foo instance NFData Foo where rnf f = foo f `deepseq` () With this change, keeping either line produces outer exception. On Tue, May 12, 2015 at 10:43 AM Alex wrote: > On Tue, 12 May 2015 06:25:44 +0000 > Alexey Shmalko wrote: > > > Seems, that you're putting it in the wrong place. Please, publish > > your code to lpaste [1]. > > > > Hmm.... Maybe you need evaluate `encode req`? > > > > I've created a test case demonstrating the behavior which is confusing > me: > > http://lpaste.net/132446 > > -- > Alex > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Tue May 12 09:39:47 2015 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Tue, 12 May 2015 16:39:47 +0700 Subject: [Haskell-beginners] why is this type wrong In-Reply-To: <5551A0D8.7070908@home.nl> References: <55519E99.606@home.nl> <5551A0D8.7070908@home.nl> Message-ID: On Tue, May 12, 2015 at 1:42 PM, Roelof Wobben wrote: -- | The main entry point. > last' :: [a] -> a > last' [x] = x > last' (x:xs) = last xs Notice that the last line does no recursion: it invokes the Prelude's definition of last. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From ns.schoe at gmail.com Tue May 12 09:45:01 2015 From: ns.schoe at gmail.com (Nicolas SCHOEMAEKER) Date: Tue, 12 May 2015 11:45:01 +0200 Subject: [Haskell-beginners] why is this type wrong In-Reply-To: References: <55519E99.606@home.nl> <5551A0D8.7070908@home.nl> Message-ID: <96ee8535-1252-45f1-8f39-abb47e4a7c56@typeapp.com> Hi In your definition, you seem to have forgotten the case when your list is empty. [x] won't bind on []. Regards, Nicolas SCHOEMAEKER (This email was composed from a mobile phone, please excuse any resulting mistakes) Web, Cloud Computing & WebRTC developer Haskell Programmer Artificial Intelligence & Robotics enthusiast On May 12, 2015, 11:40 AM, at 11:40 AM, Kim-Ee Yeoh wrote: >On Tue, May 12, 2015 at 1:42 PM, Roelof Wobben >wrote: > >-- | The main entry point. >> last' :: [a] -> a >> last' [x] = x >> last' (x:xs) = last xs > > >Notice that the last line does no recursion: it invokes the Prelude's >definition of last. > >-- Kim-Ee > > >------------------------------------------------------------------------ > >_______________________________________________ >Beginners mailing list >Beginners at haskell.org >http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Tue May 12 12:36:58 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Tue, 12 May 2015 14:36:58 +0200 Subject: [Haskell-beginners] why is this type wrong In-Reply-To: <96ee8535-1252-45f1-8f39-abb47e4a7c56@typeapp.com> References: <55519E99.606@home.nl> <5551A0D8.7070908@home.nl> <96ee8535-1252-45f1-8f39-abb47e4a7c56@typeapp.com> Message-ID: <5551F3EA.10401@home.nl> An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Tue May 12 12:39:52 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Tue, 12 May 2015 18:09:52 +0530 Subject: [Haskell-beginners] why is this type wrong In-Reply-To: <5551F3EA.10401@home.nl> References: <55519E99.606@home.nl> <5551A0D8.7070908@home.nl> <96ee8535-1252-45f1-8f39-abb47e4a7c56@typeapp.com> <5551F3EA.10401@home.nl> Message-ID: The type of (.) (.) :: (b -> c) -> (a -> b) -> a -> c Means that "last' [1,2,3]" should be a function, which it isn't You can instead try, main = (print . last') [1,2,3] Or equivalently, main = print . last' $ [1,2,3] On 12 May 2015 at 18:06, Roelof Wobben wrote: > Thanks all. > > I have now this : > > -- | The main entry point. > last' :: [a] -> Maybe a > last' [] = Nothing > last' [x] = Just x > last' (_:xs) = last' xs > > > main = print . last' [1,2,3] > > but I see this message about main : > > > > > > > > * GHC threw an exception : Couldn't match expected type ?GHC.Types.IO > a0? with actual type ?a1 -> GHC.Types.IO > ()? I work wih the fpcomplete and they demand a main > in the code . Roelof * > > > Nicolas SCHOEMAEKER schreef op 12-5-2015 om 11:45: > > Hi > > In your definition, you seem to have forgotten the case when your list is > empty. > [x] won't bind on []. > > Regards, > Nicolas SCHOEMAEKER > > (*This email was composed from a mobile phone, please** excuse** any > resulting mistakes*) > > Web, Cloud Computing & WebRTC developer > Haskell Programmer > Artificial Intelligence & Robotics enthusiast > On May 12, 2015, at 11:40 AM, Kim-Ee Yeoh wrote: >> >> >> On Tue, May 12, 2015 at 1:42 PM, Roelof Wobben wrote: >> >> -- | The main entry point. >>> last' :: [a] -> a >>> last' [x] = x >>> last' (x:xs) = last xs >> >> >> Notice that the last line does no recursion: it invokes the Prelude's >> definition of last. >> >> -- Kim-Ee >> >> ------------------------------ >> >> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > _______________________________________________ > Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > > ------------------------------ > [image: Avast logo] > > Dit e-mailbericht is gecontroleerd op virussen met Avast > antivirussoftware. > www.avast.com > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Tue May 12 12:48:42 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Tue, 12 May 2015 14:48:42 +0200 Subject: [Haskell-beginners] why is this type wrong In-Reply-To: References: <55519E99.606@home.nl> <5551A0D8.7070908@home.nl> <96ee8535-1252-45f1-8f39-abb47e4a7c56@typeapp.com> <5551F3EA.10401@home.nl> Message-ID: <5551F6AA.2050205@home.nl> An HTML attachment was scrubbed... URL: From r.wobben at home.nl Tue May 12 14:00:01 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Tue, 12 May 2015 16:00:01 +0200 Subject: [Haskell-beginners] another type problem Message-ID: <55520761.9080905@home.nl> An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Tue May 12 14:03:33 2015 From: allbery.b at gmail.com (Brandon Allbery) Date: Tue, 12 May 2015 10:03:33 -0400 Subject: [Haskell-beginners] another type problem In-Reply-To: <55520761.9080905@home.nl> References: <55520761.9080905@home.nl> Message-ID: On Tue, May 12, 2015 at 10:00 AM, Roelof Wobben wrote: > init' (x:xs) = Just (x: (init' xs)) > Remember that your init' produces Maybe [a], not [a]. -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Tue May 12 14:11:07 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Tue, 12 May 2015 16:11:07 +0200 Subject: [Haskell-beginners] another type problem In-Reply-To: References: <55520761.9080905@home.nl> Message-ID: <555209FB.6000206@home.nl> An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Tue May 12 14:16:56 2015 From: allbery.b at gmail.com (Brandon Allbery) Date: Tue, 12 May 2015 10:16:56 -0400 Subject: [Haskell-beginners] another type problem In-Reply-To: <555209FB.6000206@home.nl> References: <55520761.9080905@home.nl> <555209FB.6000206@home.nl> Message-ID: On Tue, May 12, 2015 at 10:11 AM, Roelof Wobben wrote: > I do not understand what you are saying to me. > > I know that init produces a Maybe [a] . That is why I did put a Just > before it. > You are invoking it again though, and using its result as if it produces [a] instead of Maybe [a]. -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Tue May 12 14:21:47 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Tue, 12 May 2015 16:21:47 +0200 Subject: [Haskell-beginners] another type problem In-Reply-To: References: <55520761.9080905@home.nl> <555209FB.6000206@home.nl> Message-ID: <55520C7B.5070702@home.nl> An HTML attachment was scrubbed... URL: From rasen.dubi at gmail.com Tue May 12 14:24:08 2015 From: rasen.dubi at gmail.com (Alexey Shmalko) Date: Tue, 12 May 2015 14:24:08 +0000 Subject: [Haskell-beginners] another type problem In-Reply-To: <55520C7B.5070702@home.nl> References: <55520761.9080905@home.nl> <555209FB.6000206@home.nl> <55520C7B.5070702@home.nl> Message-ID: Before cons'ing the result of init', you should check whether it's Just or Nothing. What you're doing now is something along the line with 5 : Just 3 -- this won't typecheck. On Tue, May 12, 2015 at 5:22 PM Roelof Wobben wrote: > Brandon Allbery schreef op 12-5-2015 om 16:16: > > On Tue, May 12, 2015 at 10:11 AM, Roelof Wobben wrote: > >> I do not understand what you are saying to me. >> >> I know that init produces a Maybe [a] . That is why I did put a Just >> before it. >> > > You are invoking it again though, and using its result as if it produces > [a] instead of Maybe [a]. > > -- > brandon s allbery kf8nh sine nomine > associates > allbery.b at gmail.com > ballbery at sinenomine.net > unix, openafs, kerberos, infrastructure, xmonad > http://sinenomine.net > > > _______________________________________________ > Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > What is then the right way to do. I still do not understand what you are > trying to make clear to me. > > > Roelof > > > > > ------------------------------ > [image: Avast logo] > > Dit e-mailbericht is gecontroleerd op virussen met Avast > antivirussoftware. > www.avast.com > > _______________________________________________ > 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 sumit.sahrawat.apm13 at iitbhu.ac.in Tue May 12 14:24:54 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Tue, 12 May 2015 19:54:54 +0530 Subject: [Haskell-beginners] another type problem In-Reply-To: References: <55520761.9080905@home.nl> <555209FB.6000206@home.nl> Message-ID: The type of the cons operator (:) is (:) :: a -> [a] -> [a] The way you are invoking it expects it to have the type (:) :: a -> Maybe [a] -> [a] -- not valid One solution is to write such a function yourself, while the other would be to rewrite your code to invoke it correctly. On 12 May 2015 at 19:46, Brandon Allbery wrote: > On Tue, May 12, 2015 at 10:11 AM, Roelof Wobben wrote: > >> I do not understand what you are saying to me. >> >> I know that init produces a Maybe [a] . That is why I did put a Just >> before it. >> > > You are invoking it again though, and using its result as if it produces > [a] instead of Maybe [a]. > > -- > brandon s allbery kf8nh sine nomine > associates > allbery.b at gmail.com > ballbery at sinenomine.net > unix, openafs, kerberos, infrastructure, xmonad > http://sinenomine.net > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Tue May 12 14:25:04 2015 From: allbery.b at gmail.com (Brandon Allbery) Date: Tue, 12 May 2015 10:25:04 -0400 Subject: [Haskell-beginners] another type problem In-Reply-To: <55520C7B.5070702@home.nl> References: <55520761.9080905@home.nl> <555209FB.6000206@home.nl> <55520C7B.5070702@home.nl> Message-ID: On Tue, May 12, 2015 at 10:21 AM, Roelof Wobben wrote: > What is then the right way to do. I still do not understand what you are > trying to make clear to me. > Ask yourself: what is the type of (Just (x: (init' xs))) ? -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Tue May 12 14:26:20 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Tue, 12 May 2015 19:56:20 +0530 Subject: [Haskell-beginners] another type problem In-Reply-To: References: <55520761.9080905@home.nl> <555209FB.6000206@home.nl> Message-ID: Also remember that Just has the type Just :: a -> Maybe a Thus putting in a Just doesn't help with your issue. On 12 May 2015 at 19:54, Sumit Sahrawat, Maths & Computing, IIT (BHU) < sumit.sahrawat.apm13 at iitbhu.ac.in> wrote: > The type of the cons operator (:) is > > (:) :: a -> [a] -> [a] > > The way you are invoking it expects it to have the type > > (:) :: a -> Maybe [a] -> [a] -- not valid > > One solution is to write such a function yourself, while the other would > be to rewrite your code to invoke it correctly. > > On 12 May 2015 at 19:46, Brandon Allbery wrote: > >> On Tue, May 12, 2015 at 10:11 AM, Roelof Wobben wrote: >> >>> I do not understand what you are saying to me. >>> >>> I know that init produces a Maybe [a] . That is why I did put a Just >>> before it. >>> >> >> You are invoking it again though, and using its result as if it produces >> [a] instead of Maybe [a]. >> >> -- >> brandon s allbery kf8nh sine nomine >> associates >> allbery.b at gmail.com >> ballbery at sinenomine.net >> unix, openafs, kerberos, infrastructure, xmonad >> http://sinenomine.net >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > > -- > Regards > > Sumit Sahrawat > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Tue May 12 14:27:30 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Tue, 12 May 2015 16:27:30 +0200 Subject: [Haskell-beginners] another type problem In-Reply-To: References: <55520761.9080905@home.nl> <555209FB.6000206@home.nl> <55520C7B.5070702@home.nl> Message-ID: <55520DD2.7030908@home.nl> An HTML attachment was scrubbed... URL: From rasen.dubi at gmail.com Tue May 12 14:33:19 2015 From: rasen.dubi at gmail.com (Alexey Shmalko) Date: Tue, 12 May 2015 14:33:19 +0000 Subject: [Haskell-beginners] another type problem In-Reply-To: <55520DD2.7030908@home.nl> References: <55520761.9080905@home.nl> <555209FB.6000206@home.nl> <55520C7B.5070702@home.nl> <55520DD2.7030908@home.nl> Message-ID: Try fromMaybe [1]. Examples Prelude Data.Maybe> fromMaybe [] (Just [1,2,3]) [1,2,3] Prelude Data.Maybe> fromMaybe [1,2,3] Nothing [1,2,3] [1]: https://hackage.haskell.org/package/base-4.8.0.0/docs/Data-Maybe.html#v:fromMaybe On Tue, May 12, 2015 at 5:28 PM Roelof Wobben wrote: > Oke, > > And how do I do this. Haskell is a difficult one to learn, > > Roelof > > > > Alexey Shmalko schreef op 12-5-2015 om 16:24: > > Before cons'ing the result of init', you should check whether it's Just or > Nothing. What you're doing now is something along the line with 5 : Just 3 > -- this won't typecheck. > > On Tue, May 12, 2015 at 5:22 PM Roelof Wobben wrote: > >> Brandon Allbery schreef op 12-5-2015 om 16:16: >> >> On Tue, May 12, 2015 at 10:11 AM, Roelof Wobben >> wrote: >> >>> I do not understand what you are saying to me. >>> >>> I know that init produces a Maybe [a] . That is why I did put a Just >>> before it. >>> >> >> You are invoking it again though, and using its result as if it >> produces [a] instead of Maybe [a]. >> >> -- >> brandon s allbery kf8nh sine nomine >> associates >> allbery.b at gmail.com >> ballbery at sinenomine.net >> unix, openafs, kerberos, infrastructure, xmonad >> http://sinenomine.net >> >> >> _______________________________________________ >> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> >> What is then the right way to do. I still do not understand what you >> are trying to make clear to me. >> >> >> Roelof >> >> >> >> >> ------------------------------ >> [image: Avast logo] >> >> Dit e-mailbericht is gecontroleerd op virussen met Avast >> antivirussoftware. >> www.avast.com >> >> _______________________________________________ >> 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 > > > > > ------------------------------ > [image: Avast logo] > > Dit e-mailbericht is gecontroleerd op virussen met Avast > antivirussoftware. > www.avast.com > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Tue May 12 14:44:35 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Tue, 12 May 2015 16:44:35 +0200 Subject: [Haskell-beginners] another type problem In-Reply-To: References: <55520761.9080905@home.nl> <555209FB.6000206@home.nl> <55520C7B.5070702@home.nl> <55520DD2.7030908@home.nl> Message-ID: <555211D3.4020805@home.nl> An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Tue May 12 15:31:52 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Tue, 12 May 2015 21:01:52 +0530 Subject: [Haskell-beginners] another type problem In-Reply-To: <555211D3.4020805@home.nl> References: <55520761.9080905@home.nl> <555209FB.6000206@home.nl> <55520C7B.5070702@home.nl> <55520DD2.7030908@home.nl> <555211D3.4020805@home.nl> Message-ID: On 12 May 2015 at 20:14, Roelof Wobben wrote: > Thanks, > > The right solution was this : > > init' (x:xs) = Just (x:fromMaybe xs (init' xs)) > > if I understand it right x:fromMaybe xs takes care that from xs the just > or Nothing is removed ? > > Trying it out in ghci, fromMaybe [1,2] Nothing == [1,2] fromMaybe [1,2] Just [3] == [3] It seems like that should indeed work. Roelof > > > > Alexey Shmalko schreef op 12-5-2015 om 16:33: > > Try fromMaybe [1]. Examples > > Prelude Data.Maybe> fromMaybe [] (Just [1,2,3]) > [1,2,3] > Prelude Data.Maybe> fromMaybe [1,2,3] Nothing > [1,2,3] > > [1]: > https://hackage.haskell.org/package/base-4.8.0.0/docs/Data-Maybe.html#v:fromMaybe > > On Tue, May 12, 2015 at 5:28 PM Roelof Wobben wrote: > >> Oke, >> >> And how do I do this. Haskell is a difficult one to learn, >> >> Roelof >> >> >> >> Alexey Shmalko schreef op 12-5-2015 om 16:24: >> >> Before cons'ing the result of init', you should check whether it's Just >> or Nothing. What you're doing now is something along the line with 5 : Just >> 3 -- this won't typecheck. >> >> On Tue, May 12, 2015 at 5:22 PM Roelof Wobben wrote: >> >>> Brandon Allbery schreef op 12-5-2015 om 16:16: >>> >>> On Tue, May 12, 2015 at 10:11 AM, Roelof Wobben >>> wrote: >>> >>>> I do not understand what you are saying to me. >>>> >>>> I know that init produces a Maybe [a] . That is why I did put a Just >>>> before it. >>>> >>> >>> You are invoking it again though, and using its result as if it >>> produces [a] instead of Maybe [a]. >>> >>> -- >>> brandon s allbery kf8nh sine nomine >>> associates >>> allbery.b at gmail.com >>> ballbery at sinenomine.net >>> unix, openafs, kerberos, infrastructure, xmonad >>> http://sinenomine.net >>> >>> >>> _______________________________________________ >>> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >>> What is then the right way to do. I still do not understand what you >>> are trying to make clear to me. >>> >>> >>> Roelof >>> >>> >>> >>> >>> ------------------------------ >>> [image: Avast logo] >>> >>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>> antivirussoftware. >>> www.avast.com >>> >>> _______________________________________________ >>> 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 >> >> >> >> >> ------------------------------ >> [image: Avast logo] >> >> Dit e-mailbericht is gecontroleerd op virussen met Avast >> antivirussoftware. >> www.avast.com >> >> _______________________________________________ >> 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 > > > > > ------------------------------ > [image: Avast logo] > > Dit e-mailbericht is gecontroleerd op virussen met Avast > antivirussoftware. > www.avast.com > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From alex323 at gmail.com Tue May 12 15:46:54 2015 From: alex323 at gmail.com (Alex) Date: Tue, 12 May 2015 11:46:54 -0400 Subject: [Haskell-beginners] AMQP and nested exception handlers In-Reply-To: References: <20150511221104.7ae10c40@gmail.com> <20150512021050.24aebc09@gmail.com> <20150512034349.7ce79bd4@gmail.com> Message-ID: <20150512114654.7c4c92e2@gmail.com> On Tue, 12 May 2015 08:32:08 +0000 Alexey Shmalko wrote: > Seems you lack the proper instance of NFData for Foo > > instance NFData Foo where > rnf f = foo f `deepseq` () > > With this change, keeping either line produces outer exception. > Ah, as it turns out I was using deepseq 1.3, but the Generics support wasn't available until 1.4. Upgrading to 1.4 solves the issue. Thank you for your help! -- Alex From r.wobben at home.nl Tue May 12 18:02:34 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Tue, 12 May 2015 20:02:34 +0200 Subject: [Haskell-beginners] how can I make this work Message-ID: <5552403A.7020409@home.nl> An HTML attachment was scrubbed... URL: From ahammel87 at gmail.com Tue May 12 18:11:11 2015 From: ahammel87 at gmail.com (Alex Hammel) Date: Tue, 12 May 2015 18:11:11 +0000 Subject: [Haskell-beginners] how can I make this work In-Reply-To: <5552403A.7020409@home.nl> References: <5552403A.7020409@home.nl> Message-ID: You're missing the parens around (x:yx) in the last clause. On Tue, 12 May 2015 at 11:02 Roelof Wobben wrote: > Hello, > > I try to re implement ++ > > So far I have this ; > > plusplus' :: [a] -> [a] -> [a] > plusplus' [] (xs) = xs > plusplus' [] [] = [] > plusplus' (xs) [] = xs > plusplus' (x:xs) yx = plusplus' xs x:yx > > main = print . plusplus' $ [1,2] [3,4] > > > But I still get this error message : > > src/Main.hs at 5:23-5:37 > Couldn't match expected type > a > with actual type > [a] > a > is a rigid type variable bound by the type signature for plusplus' :: [a] > -> [a] -> [a] at > /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:1:14 > Relevant bindings include yx :: [a] (bound at > /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:5:18) > xs :: [a] (bound at > /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:5:14) > x :: a (bound at > /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:5:12) > plusplus' :: [a] -> [a] -> [a] (bound at > /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:2:1) > ? > > > > > > ------------------------------ > [image: Avast logo] > > Dit e-mailbericht is gecontroleerd op virussen met Avast > antivirussoftware. > www.avast.com > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Tue May 12 18:16:06 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Tue, 12 May 2015 20:16:06 +0200 Subject: [Haskell-beginners] how can I make this work In-Reply-To: References: <5552403A.7020409@home.nl> Message-ID: <55524366.6060204@home.nl> An HTML attachment was scrubbed... URL: From ahammel87 at gmail.com Tue May 12 18:19:43 2015 From: ahammel87 at gmail.com (Alex Hammel) Date: Tue, 12 May 2015 18:19:43 +0000 Subject: [Haskell-beginners] how can I make this work In-Reply-To: <55524366.6060204@home.nl> References: <5552403A.7020409@home.nl> <55524366.6060204@home.nl> Message-ID: The relevant part of that error message is this: > The function ?[1, 2]? is applied to one argument, but its type > [t0] > has none Which means that you're trying to call a list literal as though it were a function (with one argument). Which probably means that you've got a ($) out of place. On Tue, 12 May 2015 at 11:16 Roelof Wobben wrote: > Thanks, > > Now I see the last error on the main line : > > src/Main.hs at 7:28-7:39 > Couldn't match expected type ?[t1] -> [a0]? with actual type > [t0] > The function ?[1, 2]? is applied to one argument, but its type > [t0] > has none ? In the second argument of ?($)?, namely ?[1, 2] [3, 4]? In > the expression: print . plusplus' $ [1, 2] [3, 4] > > Roelof > > > > > Alex Hammel schreef op 12-5-2015 om 20:11: > > You're missing the parens around (x:yx) in the last clause. > > On Tue, 12 May 2015 at 11:02 Roelof Wobben wrote: > >> Hello, >> >> I try to re implement ++ >> >> So far I have this ; >> >> plusplus' :: [a] -> [a] -> [a] >> plusplus' [] (xs) = xs >> plusplus' [] [] = [] >> plusplus' (xs) [] = xs >> plusplus' (x:xs) yx = plusplus' xs x:yx >> >> main = print . plusplus' $ [1,2] [3,4] >> >> >> But I still get this error message : >> >> src/Main.hs at 5:23-5:37 >> Couldn't match expected type >> a >> with actual type >> [a] >> a >> is a rigid type variable bound by the type signature for plusplus' :: >> [a] -> [a] -> [a] at >> /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:1:14 >> Relevant bindings include yx :: [a] (bound at >> /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:5:18) >> xs :: [a] (bound at >> /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:5:14) >> x :: a (bound at >> /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:5:12) >> plusplus' :: [a] -> [a] -> [a] (bound at >> /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:2:1) >> ? >> >> >> >> >> >> ------------------------------ >> [image: Avast logo] >> >> Dit e-mailbericht is gecontroleerd op virussen met Avast >> antivirussoftware. >> www.avast.com >> >> _______________________________________________ >> 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 > > > > > ------------------------------ > [image: Avast logo] > > Dit e-mailbericht is gecontroleerd op virussen met Avast > antivirussoftware. > www.avast.com > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Tue May 12 18:33:05 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Tue, 12 May 2015 20:33:05 +0200 Subject: [Haskell-beginners] how can I make this work In-Reply-To: References: <5552403A.7020409@home.nl> <55524366.6060204@home.nl> Message-ID: <55524761.7090308@home.nl> An HTML attachment was scrubbed... URL: From jonathan.skarstedt at gmail.com Tue May 12 18:58:41 2015 From: jonathan.skarstedt at gmail.com (=?UTF-8?Q?Jonathan_Sk=C3=A5rstedt?=) Date: Tue, 12 May 2015 20:58:41 +0200 Subject: [Haskell-beginners] how can I make this work In-Reply-To: <55524761.7090308@home.nl> References: <5552403A.7020409@home.nl> <55524366.6060204@home.nl> <55524761.7090308@home.nl> Message-ID: Hello! I will call plusplus' by pp' in the text below 1. Your pp' gives a warning, namely that the patterns pp' [] xs = xs pp' [] [] = [] are overlapping. This is because of pattern matching working top-down ie if I give the input *pp' [] [] *it will match both your function entry points at *pp' [] xs* and *pp' [] []*. We don't really need *pp' [] []* as *pp' [] ys = ys *will give the correct answer even if ys is an empty list. 2. In your last function body you have this expression pp' (x:xs) ys = pp' xs (x:ys) this will not do what you expect, consider the flow below. I will call pp' on two strings "ABC" and "DEF" Lets extend this function pp' (A:BC) DEF = pp' BC (A:DEF) pp' (B:C) ADEF = pp' C (B:ADEF) pp' C:[] BADEF = pp' [] (C:BADEF) pp' [] CBADEF = CBADEF -- <- base case As you see, it will pick the first of xs to put first on ys but is this what we want? For one recursion, yes but after that it gets a bit weird. The second recursion will flip the order of the resulting list by adding the first object at the start first, instead of last. We actually don't want our construction (the colon :) to work from inside the recursive call (pp' xs (x:ys)), we want to move it outside, like this, and just like we did in init: pp' (x:xs) ys = *x: *pp' xs ys 2015-05-12 20:33 GMT+02:00 Roelof Wobben : > pfff, I got grazy here > > On this function it works fine : > > -- | The main entry point. > init' :: [a] -> Maybe [a] > init' [] = Nothing > init' [x] = Just [] > init' (x:xs) = Just (x:fromMaybe xs (init' xs)) > > main = print . init' $ [1,3] > > > and on this one it does not work : > > plusplus' :: [a] -> [a] -> [a] > plusplus' [] (xs) = xs > plusplus' [] [] = [] > plusplus' (xs) [] = xs > plusplus' (x:xs) yx = plusplus' xs (x:yx) > > > main = print . plusplus' $ [1,2] [3, 4] > > Roelof > > > > > Alex Hammel schreef op 12-5-2015 om 20:19: > > The relevant part of that error message is this: > > > The function ?[1, 2]? is applied to one argument, but its type > > [t0] > > has none > > Which means that you're trying to call a list literal as though it were a > function (with one argument). Which probably means that you've got a ($) > out of place. > > > On Tue, 12 May 2015 at 11:16 Roelof Wobben wrote: > >> Thanks, >> >> Now I see the last error on the main line : >> >> src/Main.hs at 7:28-7:39 >> Couldn't match expected type ?[t1] -> [a0]? with actual type >> [t0] >> The function ?[1, 2]? is applied to one argument, but its type >> [t0] >> has none ? In the second argument of ?($)?, namely ?[1, 2] [3, 4]? In >> the expression: print . plusplus' $ [1, 2] [3, 4] >> >> Roelof >> >> >> >> >> Alex Hammel schreef op 12-5-2015 om 20:11: >> >> You're missing the parens around (x:yx) in the last clause. >> >> On Tue, 12 May 2015 at 11:02 Roelof Wobben wrote: >> >>> Hello, >>> >>> I try to re implement ++ >>> >>> So far I have this ; >>> >>> plusplus' :: [a] -> [a] -> [a] >>> plusplus' [] (xs) = xs >>> plusplus' [] [] = [] >>> plusplus' (xs) [] = xs >>> plusplus' (x:xs) yx = plusplus' xs x:yx >>> >>> main = print . plusplus' $ [1,2] [3,4] >>> >>> >>> But I still get this error message : >>> >>> src/Main.hs at 5:23-5:37 >>> Couldn't match expected type >>> a >>> with actual type >>> [a] >>> a >>> is a rigid type variable bound by the type signature for plusplus' :: >>> [a] -> [a] -> [a] at >>> /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:1:14 >>> Relevant bindings include yx :: [a] (bound at >>> /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:5:18) >>> xs :: [a] (bound at >>> /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:5:14) >>> x :: a (bound at >>> /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:5:12) >>> plusplus' :: [a] -> [a] -> [a] (bound at >>> /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:2:1) >>> ? >>> >>> >>> >>> >>> >>> ------------------------------ >>> [image: Avast logo] >>> >>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>> antivirussoftware. >>> www.avast.com >>> >>> _______________________________________________ >>> 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 >> >> >> >> >> ------------------------------ >> [image: Avast logo] >> >> Dit e-mailbericht is gecontroleerd op virussen met Avast >> antivirussoftware. >> www.avast.com >> >> _______________________________________________ >> 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 > > > > > ------------------------------ > [image: Avast logo] > > Dit e-mailbericht is gecontroleerd op virussen met Avast > antivirussoftware. > www.avast.com > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Jonathan Sk?rstedt Bergsg?rdsg?rdet 39 Lgh 1108 424 32 G?teborg Mobil: 073 - 76 20 20 7 -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Tue May 12 19:14:59 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Tue, 12 May 2015 21:14:59 +0200 Subject: [Haskell-beginners] how can I make this work In-Reply-To: References: <5552403A.7020409@home.nl> <55524366.6060204@home.nl> <55524761.7090308@home.nl> Message-ID: <55525133.9000504@home.nl> An HTML attachment was scrubbed... URL: From r.wobben at home.nl Wed May 13 06:10:17 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Wed, 13 May 2015 08:10:17 +0200 Subject: [Haskell-beginners] Are these solution the Haskell way ? Message-ID: <5552EAC9.7060900@home.nl> Hello, For practising pattern matching and recursion I did recreate some commands of Data,list. My re-implementation of ++ : plusplus :: [a] -> [a] -> [a] plusplus [] [] = [] ; plusplus [] (xs) = xs plusplus (xs) [] = xs plusplus (xs) yx = plusplus' (reverse xs) yx plusplus' :: [a] -> [a] -> [a] plusplus' [] (xs) = xs plusplus' (x:xs) yx = plusplus' xs (x:yx) main = print $ plusplus ["a","b"] ["c","d"] my re-implementation of init : import Data.Maybe -- | The main entry point. init' :: [a] -> Maybe [a] init' [] = Nothing init' [x] = Just [] init' (x:xs) = Just (x:fromMaybe xs (init' xs)) main = print . init' $ [1,3] my re-implementation of last : -- | The main entry point. last' :: [a] -> Maybe a last' [] = Nothing last' [x] = Just x last' (_:xs) = last' xs main = print . last' $ [] Now I wonder if these solutions are the haskell way ? if not so, how can I improve them , Roelof --- Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. http://www.avast.com From dani at dpwright.com Wed May 13 06:27:23 2015 From: dani at dpwright.com (Daniel P. Wright) Date: Wed, 13 May 2015 15:27:23 +0900 Subject: [Haskell-beginners] Are these solution the Haskell way ? In-Reply-To: <5552EAC9.7060900@home.nl> References: <5552EAC9.7060900@home.nl> Message-ID: Hi Roelof, If you don't consider it cheating (and I suggest you shouldn't, having had a stab at the answers), you will find great enlightenment looking at how these functions are *actually* implemented in the wild. Did you know that there is a "source" link for each function on Hackage? By clicking on that, for your first example, you can compare the actual implementation of (++) with your "plusplus" function: http://hackage.haskell.org/package/base-4.8.0.0/docs/src/GHC-Base.html#%2B%2B (By the way, it's that function in particular that gave me one of my first "Aha!" moments in Haskell... it's quite beautiful in its simplicity). One thing with viewing the source on Hackage is that sometimes it can be a little more confusing than it needs to be for the sake of efficiency. A really good source for good, readable examples of Prelude functions in Haskell is the Haskell Report: https://www.haskell.org/onlinereport/standard-prelude.html (In this case, though, the implementation is the same). Having a shot at defining these library functions yourself, as you have done, and then comparing your version with the "official" version in the prelude is a great way to learn good style! -Dani. 2015-05-13 15:10 GMT+09:00 Roelof Wobben : > Hello, > > For practising pattern matching and recursion I did recreate some commands > of Data,list. > > My re-implementation of ++ : > > plusplus :: [a] -> [a] -> [a] > plusplus [] [] = [] ; > plusplus [] (xs) = xs > plusplus (xs) [] = xs > plusplus (xs) yx = plusplus' (reverse xs) yx > > plusplus' :: [a] -> [a] -> [a] > plusplus' [] (xs) = xs > plusplus' (x:xs) yx = plusplus' xs (x:yx) > > main = print $ plusplus ["a","b"] ["c","d"] > > my re-implementation of init : > > import Data.Maybe > > -- | The main entry point. > init' :: [a] -> Maybe [a] > init' [] = Nothing > init' [x] = Just [] > init' (x:xs) = Just (x:fromMaybe xs (init' xs)) > > main = print . init' $ [1,3] > > > my re-implementation of last : > > -- | The main entry point. > last' :: [a] -> Maybe a > last' [] = Nothing > last' [x] = Just x > last' (_:xs) = last' xs > > main = print . last' $ [] > > Now I wonder if these solutions are the haskell way ? if not so, how can I > improve them , > > Roelof > > > --- > Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. > http://www.avast.com > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Wed May 13 06:39:51 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Wed, 13 May 2015 08:39:51 +0200 Subject: [Haskell-beginners] Are these solution the Haskell way ? In-Reply-To: References: <5552EAC9.7060900@home.nl> Message-ID: <5552F1B7.1080708@home.nl> An HTML attachment was scrubbed... URL: From dani at dpwright.com Wed May 13 06:52:14 2015 From: dani at dpwright.com (Daniel P. Wright) Date: Wed, 13 May 2015 15:52:14 +0900 Subject: [Haskell-beginners] Are these solution the Haskell way ? In-Reply-To: <5552F1B7.1080708@home.nl> References: <5552EAC9.7060900@home.nl> <5552F1B7.1080708@home.nl> Message-ID: Ah, that's just a small syntactic issue -- in Haskell, operators are infix (go between the arguments) by default, but named functions are not. So you would have to write it: plusplus [] xs = xs plusplus (x:xs) ys = x : plusplus xs ys 2015-05-13 15:39 GMT+09:00 Roelof Wobben : > Thanks, > > If I re-implement it like this : > > plusplus :: [a] -> [a] -> [a] > plusplus [] (xs) = xs > plusplus (x:xs) yx = x : xs plusplus yx > > main = print $ ["a","b"] plusplus ["c","d"] > > > I see this error appear : > > src/Main.hs at 3:26-3:40 > Couldn't match expected type ?([a0] -> [a0] -> [a0]) -> [a] -> [a]? with > actual type > [a] > Relevant bindings include yx :: [a] (bound at > /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:3:17) > xs :: [a] (bound at > /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:3:13) > x :: a (bound at > /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:3:11) > plusplus :: [a] -> [a] -> [a] (bound at > /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:2:1) > The function > xs > is applied to two arguments, but its type > [a] > has none ? > > So for me not a aha moment. I was hoping I would get it > > Roelof > > Daniel P. Wright schreef op 13-5-2015 om 8:27: > > Hi Roelof, > > If you don't consider it cheating (and I suggest you shouldn't, having > had a stab at the answers), you will find great enlightenment looking at > how these functions are *actually* implemented in the wild. Did you know > that there is a "source" link for each function on Hackage? By clicking on > that, for your first example, you can compare the actual implementation of > (++) with your "plusplus" function: > > > http://hackage.haskell.org/package/base-4.8.0.0/docs/src/GHC-Base.html#%2B%2B > > (By the way, it's that function in particular that gave me one of my > first "Aha!" moments in Haskell... it's quite beautiful in its simplicity). > > One thing with viewing the source on Hackage is that sometimes it can be > a little more confusing than it needs to be for the sake of efficiency. A > really good source for good, readable examples of Prelude functions in > Haskell is the Haskell Report: > > https://www.haskell.org/onlinereport/standard-prelude.html > > (In this case, though, the implementation is the same). > > Having a shot at defining these library functions yourself, as you have > done, and then comparing your version with the "official" version in the > prelude is a great way to learn good style! > > -Dani. > > 2015-05-13 15:10 GMT+09:00 Roelof Wobben : > >> Hello, >> >> For practising pattern matching and recursion I did recreate some >> commands of Data,list. >> >> My re-implementation of ++ : >> >> plusplus :: [a] -> [a] -> [a] >> plusplus [] [] = [] ; >> plusplus [] (xs) = xs >> plusplus (xs) [] = xs >> plusplus (xs) yx = plusplus' (reverse xs) yx >> >> plusplus' :: [a] -> [a] -> [a] >> plusplus' [] (xs) = xs >> plusplus' (x:xs) yx = plusplus' xs (x:yx) >> >> main = print $ plusplus ["a","b"] ["c","d"] >> >> my re-implementation of init : >> >> import Data.Maybe >> >> -- | The main entry point. >> init' :: [a] -> Maybe [a] >> init' [] = Nothing >> init' [x] = Just [] >> init' (x:xs) = Just (x:fromMaybe xs (init' xs)) >> >> main = print . init' $ [1,3] >> >> >> my re-implementation of last : >> >> -- | The main entry point. >> last' :: [a] -> Maybe a >> last' [] = Nothing >> last' [x] = Just x >> last' (_:xs) = last' xs >> >> main = print . last' $ [] >> >> Now I wonder if these solutions are the haskell way ? if not so, how can >> I improve them , >> >> Roelof >> >> >> --- >> Dit e-mailbericht is gecontroleerd op virussen met Avast >> antivirussoftware. >> http://www.avast.com >> >> _______________________________________________ >> 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 > > > > > ------------------------------ > [image: Avast logo] > > Dit e-mailbericht is gecontroleerd op virussen met Avast > antivirussoftware. > www.avast.com > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Wed May 13 06:55:33 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Wed, 13 May 2015 08:55:33 +0200 Subject: [Haskell-beginners] Are these solution the Haskell way ? In-Reply-To: References: <5552EAC9.7060900@home.nl> <5552F1B7.1080708@home.nl> Message-ID: <5552F565.1010907@home.nl> An HTML attachment was scrubbed... URL: From dani at dpwright.com Wed May 13 07:08:59 2015 From: dani at dpwright.com (Daniel P. Wright) Date: Wed, 13 May 2015 16:08:59 +0900 Subject: [Haskell-beginners] Are these solution the Haskell way ? In-Reply-To: <5552F565.1010907@home.nl> References: <5552EAC9.7060900@home.nl> <5552F1B7.1080708@home.nl> <5552F565.1010907@home.nl> Message-ID: Think about what the possible values of "xs" might be, and trace through the next call to "plusplus xs ys". It would help if I didn't name the variables stupidly... here is a slightly better version: plusplus [] ys = ys plusplus (x:xs) ys = x : plusplus xs ys If it helps, try tracing through the steps required to evaluate "plusplus [1, 2] [3, 4]" manually (using a pen and paper, not on the computer) 2015-05-13 15:55 GMT+09:00 Roelof Wobben : > Thanks, > > So the answer is x and the rest of xs and ys. > How do x then get added to ys. > > Roelof > > Daniel P. Wright schreef op 13-5-2015 om 8:52: > > Ah, that's just a small syntactic issue -- in Haskell, operators are infix > (go between the arguments) by default, but named functions are not. So you > would have to write it: > > plusplus [] xs = xs > plusplus (x:xs) ys = x : plusplus xs ys > > > 2015-05-13 15:39 GMT+09:00 Roelof Wobben : > >> Thanks, >> >> If I re-implement it like this : >> >> plusplus :: [a] -> [a] -> [a] >> plusplus [] (xs) = xs >> plusplus (x:xs) yx = x : xs plusplus yx >> >> main = print $ ["a","b"] plusplus ["c","d"] >> >> >> I see this error appear : >> >> src/Main.hs at 3:26-3:40 >> Couldn't match expected type ?([a0] -> [a0] -> [a0]) -> [a] -> [a]? with >> actual type >> [a] >> Relevant bindings include yx :: [a] (bound at >> /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:3:17) >> xs :: [a] (bound at >> /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:3:13) >> x :: a (bound at >> /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:3:11) >> plusplus :: [a] -> [a] -> [a] (bound at >> /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:2:1) >> The function >> xs >> is applied to two arguments, but its type >> [a] >> has none ? >> >> So for me not a aha moment. I was hoping I would get it >> >> Roelof >> >> Daniel P. Wright schreef op 13-5-2015 om 8:27: >> >> Hi Roelof, >> >> If you don't consider it cheating (and I suggest you shouldn't, having >> had a stab at the answers), you will find great enlightenment looking at >> how these functions are *actually* implemented in the wild. Did you know >> that there is a "source" link for each function on Hackage? By clicking on >> that, for your first example, you can compare the actual implementation of >> (++) with your "plusplus" function: >> >> >> http://hackage.haskell.org/package/base-4.8.0.0/docs/src/GHC-Base.html#%2B%2B >> >> (By the way, it's that function in particular that gave me one of my >> first "Aha!" moments in Haskell... it's quite beautiful in its simplicity). >> >> One thing with viewing the source on Hackage is that sometimes it can >> be a little more confusing than it needs to be for the sake of efficiency. >> A really good source for good, readable examples of Prelude functions in >> Haskell is the Haskell Report: >> >> https://www.haskell.org/onlinereport/standard-prelude.html >> >> (In this case, though, the implementation is the same). >> >> Having a shot at defining these library functions yourself, as you have >> done, and then comparing your version with the "official" version in the >> prelude is a great way to learn good style! >> >> -Dani. >> >> 2015-05-13 15:10 GMT+09:00 Roelof Wobben : >> >>> Hello, >>> >>> For practising pattern matching and recursion I did recreate some >>> commands of Data,list. >>> >>> My re-implementation of ++ : >>> >>> plusplus :: [a] -> [a] -> [a] >>> plusplus [] [] = [] ; >>> plusplus [] (xs) = xs >>> plusplus (xs) [] = xs >>> plusplus (xs) yx = plusplus' (reverse xs) yx >>> >>> plusplus' :: [a] -> [a] -> [a] >>> plusplus' [] (xs) = xs >>> plusplus' (x:xs) yx = plusplus' xs (x:yx) >>> >>> main = print $ plusplus ["a","b"] ["c","d"] >>> >>> my re-implementation of init : >>> >>> import Data.Maybe >>> >>> -- | The main entry point. >>> init' :: [a] -> Maybe [a] >>> init' [] = Nothing >>> init' [x] = Just [] >>> init' (x:xs) = Just (x:fromMaybe xs (init' xs)) >>> >>> main = print . init' $ [1,3] >>> >>> >>> my re-implementation of last : >>> >>> -- | The main entry point. >>> last' :: [a] -> Maybe a >>> last' [] = Nothing >>> last' [x] = Just x >>> last' (_:xs) = last' xs >>> >>> main = print . last' $ [] >>> >>> Now I wonder if these solutions are the haskell way ? if not so, how can >>> I improve them , >>> >>> Roelof >>> >>> >>> --- >>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>> antivirussoftware. >>> http://www.avast.com >>> >>> _______________________________________________ >>> 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 >> >> >> >> >> ------------------------------ >> [image: Avast logo] >> >> Dit e-mailbericht is gecontroleerd op virussen met Avast >> antivirussoftware. >> www.avast.com >> >> >> _______________________________________________ >> 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 > > > > > ------------------------------ > [image: Avast logo] > > Dit e-mailbericht is gecontroleerd op virussen met Avast > antivirussoftware. > www.avast.com > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From raabe at froglogic.com Wed May 13 07:17:46 2015 From: raabe at froglogic.com (Frerich Raabe) Date: Wed, 13 May 2015 09:17:46 +0200 Subject: [Haskell-beginners] =?utf-8?q?Are_these_solution_the_Haskell_way_?= =?utf-8?q?=3F?= In-Reply-To: <5552F565.1010907@home.nl> References: <5552EAC9.7060900@home.nl> <5552F1B7.1080708@home.nl> <5552F565.1010907@home.nl> Message-ID: <83718382b5ad7bbd406b65fbde40dbb4@roundcube.froglogic.com> Roelof, since these functions are all pure (i.e. solely defined through their arguments) you can apply equational reasoning, which means: everytime the 'plusplus' function is called you can replace that call with the definition of the function without changing the behaviour of the program. That allows you to just evaluate a call manually, expanding each function call by hand. I added some extra parentheses to emphasize the functions being evaluate: plusplus [1,2,3] [4,5,6] | apply 'plusplus', second pattern for 'plusplus' matches == 1 : (plusplus [2,3] [4,5,6]) | " == 1 : (2 : (plusplus [3] [4,5,6])) | " == 1 : (2 : (3 : (plusplus [] [4,5,6]))) | apply 'plusplus', first pattern for 'plusplus' matches == 1 : (2 : (3 : [4,5,6]) | apply (:) function == 1 : (2 : [3,4,5,6]) | " == 1 : [2,3,4,5,6] | " == [1,2,3,4,5,6] | " On 2015-05-13 08:55, Roelof Wobben wrote: > Thanks, > > So the answer is x and the rest of xs and ys. > How do x then get added to ys. > > Roelof > > Daniel P. Wright schreef op 13-5-2015 om 8:52: > >> Ah, that's just a small syntactic issue -- in Haskell, operators are infix >> (go between the arguments) by default, but named functions are >> not. So you would have to write it: >> >> plusplus [] xs = xs >> plusplus (x:xs) ys = x : plusplus xs ys >> >> 2015-05-13 15:39 GMT+09:00 Roelof Wobben : >> >> Thanks, >> >> If I re-implement it like this : >> >> plusplus :: [a] -> [a] -> [a] >> plusplus [] (xs) = xs >> plusplus (x:xs) yx = x : xs plusplus yx >> >> main = print $ ["a","b"] plusplus ["c","d"] >> >> I see this error appear : >> >> src/Main.hs at 3:26-3:40 >> Couldn't match expected type ?([a0] -> [a0] -> [a0]) -> [a] -> [a]? with >> actual type >> [a] Relevant bindings include yx :: [a] (bound at >> /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:3:17) >> xs :: >> [a] (bound at >> /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:3:13) >> x :: a (bound at >> /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:3:11) >> plusplus :: [a] -> [a] -> [a] (bound at >> /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:2:1) >> The function >> xs is applied to two arguments, but its type >> [a] has none ? >> >> So for me not a aha moment. I was hoping I would get it >> >> Roelof >> >> Daniel P. Wright schreef op 13-5-2015 om 8:27: >> >> Hi Roelof, >> >> If you don't consider it cheating (and I suggest you shouldn't, having had >> a stab at the answers), you will find great enlightenment looking >> at how these functions are *actually* implemented in the wild. Did you know >> that there is a "source" link for each function on Hackage? By >> clicking on that, for your first example, you can compare the actual >> implementation of (++) with your "plusplus" function: >> >> http://hackage.haskell.org/package/base-4.8.0.0/docs/src/GHC-Base.html#%2B%2B >> [2] >> >> (By the way, it's that function in particular that gave me one of my first >> "Aha!" moments in Haskell... it's quite beautiful in its >> simplicity). >> >> One thing with viewing the source on Hackage is that sometimes it can be a >> little more confusing than it needs to be for the sake of >> efficiency. A really good source for good, readable examples of Prelude >> functions in Haskell is the Haskell Report: >> >> https://www.haskell.org/onlinereport/standard-prelude.html [3] >> >> (In this case, though, the implementation is the same). >> >> Having a shot at defining these library functions yourself, as you have >> done, and then comparing your version with the "official" version in >> the prelude is a great way to learn good style! >> >> -Dani. >> >> 2015-05-13 15:10 GMT+09:00 Roelof Wobben : >> Hello, >> >> For practising pattern matching and recursion I did recreate some commands >> of Data,list. >> >> My re-implementation of ++ : >> >> plusplus :: [a] -> [a] -> [a] >> plusplus [] [] = [] ; >> plusplus [] (xs) = xs >> plusplus (xs) [] = xs >> plusplus (xs) yx = plusplus' (reverse xs) yx >> >> plusplus' :: [a] -> [a] -> [a] >> plusplus' [] (xs) = xs >> plusplus' (x:xs) yx = plusplus' xs (x:yx) >> >> main = print $ plusplus ["a","b"] ["c","d"] >> >> my re-implementation of init : >> >> import Data.Maybe >> >> -- | The main entry point. >> init' :: [a] -> Maybe [a] >> init' [] = Nothing >> init' [x] = Just [] >> init' (x:xs) = Just (x:fromMaybe xs (init' xs)) >> >> main = print . init' $ [1,3] >> >> my re-implementation of last : >> >> -- | The main entry point. >> last' :: [a] -> Maybe a >> last' [] = Nothing >> last' [x] = Just x >> last' (_:xs) = last' xs >> >> main = print . last' $ [] >> >> Now I wonder if these solutions are the haskell way ? if not so, how can I >> improve them , >> >> Roelof >> >> --- >> Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. >> http://www.avast.com [4] >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners [1] >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners [1] > > ------------------------- > > [5] > > Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. > www.avast.com [5] > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners [1] > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners [1] > > ------------------------- > > [5] > > Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. > www.avast.com [5] > > > > Links: > ------ > [1] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > [2] > http://hackage.haskell.org/package/base-4.8.0.0/docs/src/GHC-Base.html#%2B%2B > [3] https://www.haskell.org/onlinereport/standard-prelude.html > [4] http://www.avast.com > [5] http://www.avast.com/ > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -- Frerich Raabe - raabe at froglogic.com www.froglogic.com - Multi-Platform GUI Testing From r.wobben at home.nl Wed May 13 07:20:57 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Wed, 13 May 2015 09:20:57 +0200 Subject: [Haskell-beginners] Are these solution the Haskell way ? In-Reply-To: References: <5552EAC9.7060900@home.nl> <5552F1B7.1080708@home.nl> <5552F565.1010907@home.nl> Message-ID: <5552FB59.8080702@home.nl> An HTML attachment was scrubbed... URL: From akaberto at gmail.com Wed May 13 08:57:10 2015 From: akaberto at gmail.com (akash g) Date: Wed, 13 May 2015 14:27:10 +0530 Subject: [Haskell-beginners] another type problem In-Reply-To: References: <55520761.9080905@home.nl> <555209FB.6000206@home.nl> <55520C7B.5070702@home.nl> <55520DD2.7030908@home.nl> <555211D3.4020805@home.nl> Message-ID: Why not just? ================== init' [] = Nothing init' xs = Just xs ================== Meets your type sig and is also has a time complexity of O(1) instead of O(n) which will be the time complexity in the solution involving fromMaybe. Maybe I'm missing something. Perhaps it'd help us help you if you'd be a bit more clear on what you want to achieve. On Tue, May 12, 2015 at 9:01 PM, Sumit Sahrawat, Maths & Computing, IIT (BHU) wrote: > On 12 May 2015 at 20:14, Roelof Wobben wrote: > >> Thanks, >> >> The right solution was this : >> >> init' (x:xs) = Just (x:fromMaybe xs (init' xs)) >> >> if I understand it right x:fromMaybe xs takes care that from xs the just >> or Nothing is removed ? >> >> > Trying it out in ghci, > > fromMaybe [1,2] Nothing == [1,2] > fromMaybe [1,2] Just [3] == [3] > > It seems like that should indeed work. > > Roelof >> >> >> >> Alexey Shmalko schreef op 12-5-2015 om 16:33: >> >> Try fromMaybe [1]. Examples >> >> Prelude Data.Maybe> fromMaybe [] (Just [1,2,3]) >> [1,2,3] >> Prelude Data.Maybe> fromMaybe [1,2,3] Nothing >> [1,2,3] >> >> [1]: >> https://hackage.haskell.org/package/base-4.8.0.0/docs/Data-Maybe.html#v:fromMaybe >> >> On Tue, May 12, 2015 at 5:28 PM Roelof Wobben wrote: >> >>> Oke, >>> >>> And how do I do this. Haskell is a difficult one to learn, >>> >>> Roelof >>> >>> >>> >>> Alexey Shmalko schreef op 12-5-2015 om 16:24: >>> >>> Before cons'ing the result of init', you should check whether it's Just >>> or Nothing. What you're doing now is something along the line with 5 : Just >>> 3 -- this won't typecheck. >>> >>> On Tue, May 12, 2015 at 5:22 PM Roelof Wobben wrote: >>> >>>> Brandon Allbery schreef op 12-5-2015 om 16:16: >>>> >>>> On Tue, May 12, 2015 at 10:11 AM, Roelof Wobben >>>> wrote: >>>> >>>>> I do not understand what you are saying to me. >>>>> >>>>> I know that init produces a Maybe [a] . That is why I did put a Just >>>>> before it. >>>>> >>>> >>>> You are invoking it again though, and using its result as if it >>>> produces [a] instead of Maybe [a]. >>>> >>>> -- >>>> brandon s allbery kf8nh sine nomine >>>> associates >>>> allbery.b at gmail.com >>>> ballbery at sinenomine.net >>>> unix, openafs, kerberos, infrastructure, xmonad >>>> http://sinenomine.net >>>> >>>> >>>> _______________________________________________ >>>> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>>> >>>> What is then the right way to do. I still do not understand what you >>>> are trying to make clear to me. >>>> >>>> >>>> Roelof >>>> >>>> >>>> >>>> >>>> ------------------------------ >>>> [image: Avast logo] >>>> >>>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>>> antivirussoftware. >>>> www.avast.com >>>> >>>> _______________________________________________ >>>> 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 >>> >>> >>> >>> >>> ------------------------------ >>> [image: Avast logo] >>> >>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>> antivirussoftware. >>> www.avast.com >>> >>> _______________________________________________ >>> 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 >> >> >> >> >> ------------------------------ >> [image: Avast logo] >> >> Dit e-mailbericht is gecontroleerd op virussen met Avast >> antivirussoftware. >> www.avast.com >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > > -- > Regards > > Sumit Sahrawat > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Wed May 13 09:17:44 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Wed, 13 May 2015 11:17:44 +0200 Subject: [Haskell-beginners] another type problem In-Reply-To: References: <55520761.9080905@home.nl> <555209FB.6000206@home.nl> <55520C7B.5070702@home.nl> <55520DD2.7030908@home.nl> <555211D3.4020805@home.nl> Message-ID: <555316B8.2000408@home.nl> An HTML attachment was scrubbed... URL: From akaberto at gmail.com Wed May 13 09:49:27 2015 From: akaberto at gmail.com (akash g) Date: Wed, 13 May 2015 15:19:27 +0530 Subject: [Haskell-beginners] another type problem In-Reply-To: <555316B8.2000408@home.nl> References: <55520761.9080905@home.nl> <555209FB.6000206@home.nl> <55520C7B.5070702@home.nl> <55520DD2.7030908@home.nl> <555211D3.4020805@home.nl> <555316B8.2000408@home.nl> Message-ID: Ah, but it doesn't. Since this is a functional language, we have a pointer to it. In fact, all it does is rap it around in the Maybe type. Also, my version doesn't do what you want. One way to do that would be what you have. Or something like this. The following turns the partial function in the Prelude to one that is safe ========== import Data.List init' :: [a] -> Maybe [a] init' [] = Nothing -- Base case init' xs = Just $ tail xs -- Inductive case ========== On Wed, May 13, 2015 at 2:47 PM, Roelof Wobben wrote: > Hello, > > What my intention was to make a safe version of the init function found in > Data.list so it procudes a list without the last item. > At first look your function procudes the whole list again. > > Roelof > > > > akash g schreef op 13-5-2015 om 10:57: > > Why not just? > > ================== > init' [] = Nothing > init' xs = Just xs > ================== > > Meets your type sig and is also has a time complexity of O(1) instead of > O(n) which will be the time complexity in the solution involving > fromMaybe. Maybe I'm missing something. > > Perhaps it'd help us help you if you'd be a bit more clear on what you > want to achieve. > > On Tue, May 12, 2015 at 9:01 PM, Sumit Sahrawat, Maths & Computing, IIT > (BHU) wrote: > >> On 12 May 2015 at 20:14, Roelof Wobben wrote: >> >>> Thanks, >>> >>> The right solution was this : >>> >>> init' (x:xs) = Just (x:fromMaybe xs (init' xs)) >>> >>> if I understand it right x:fromMaybe xs takes care that from xs the just >>> or Nothing is removed ? >>> >>> >> Trying it out in ghci, >> >> fromMaybe [1,2] Nothing == [1,2] >> fromMaybe [1,2] Just [3] == [3] >> >> It seems like that should indeed work. >> >> Roelof >>> >>> >>> >>> Alexey Shmalko schreef op 12-5-2015 om 16:33: >>> >>> Try fromMaybe [1]. Examples >>> >>> Prelude Data.Maybe> fromMaybe [] (Just [1,2,3]) >>> [1,2,3] >>> Prelude Data.Maybe> fromMaybe [1,2,3] Nothing >>> [1,2,3] >>> >>> [1]: >>> https://hackage.haskell.org/package/base-4.8.0.0/docs/Data-Maybe.html#v:fromMaybe >>> >>> On Tue, May 12, 2015 at 5:28 PM Roelof Wobben wrote: >>> >>>> Oke, >>>> >>>> And how do I do this. Haskell is a difficult one to learn, >>>> >>>> Roelof >>>> >>>> >>>> >>>> Alexey Shmalko schreef op 12-5-2015 om 16:24: >>>> >>>> Before cons'ing the result of init', you should check whether it's Just >>>> or Nothing. What you're doing now is something along the line with 5 : Just >>>> 3 -- this won't typecheck. >>>> >>>> On Tue, May 12, 2015 at 5:22 PM Roelof Wobben wrote: >>>> >>>>> Brandon Allbery schreef op 12-5-2015 om 16:16: >>>>> >>>>> On Tue, May 12, 2015 at 10:11 AM, Roelof Wobben >>>>> wrote: >>>>> >>>>>> I do not understand what you are saying to me. >>>>>> >>>>>> I know that init produces a Maybe [a] . That is why I did put a Just >>>>>> before it. >>>>>> >>>>> >>>>> You are invoking it again though, and using its result as if it >>>>> produces [a] instead of Maybe [a]. >>>>> >>>>> -- >>>>> brandon s allbery kf8nh sine nomine >>>>> associates >>>>> allbery.b at gmail.com >>>>> ballbery at sinenomine.net >>>>> unix, openafs, kerberos, infrastructure, xmonad >>>>> http://sinenomine.net >>>>> >>>>> >>>>> _______________________________________________ >>>>> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>> >>>>> >>>>> What is then the right way to do. I still do not understand what you >>>>> are trying to make clear to me. >>>>> >>>>> >>>>> Roelof >>>>> >>>>> >>>>> >>>>> >>>>> ------------------------------ >>>>> [image: Avast logo] >>>>> >>>>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>>>> antivirussoftware. >>>>> www.avast.com >>>>> >>>>> _______________________________________________ >>>>> 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 >>>> >>>> >>>> >>>> >>>> ------------------------------ >>>> [image: Avast logo] >>>> >>>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>>> antivirussoftware. >>>> www.avast.com >>>> >>>> _______________________________________________ >>>> 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 >>> >>> >>> >>> >>> ------------------------------ >>> [image: Avast logo] >>> >>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>> antivirussoftware. >>> www.avast.com >>> >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> >> >> -- >> Regards >> >> Sumit Sahrawat >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > > _______________________________________________ > Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > > ------------------------------ > [image: Avast logo] > > Dit e-mailbericht is gecontroleerd op virussen met Avast > antivirussoftware. > www.avast.com > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From akaberto at gmail.com Wed May 13 09:53:01 2015 From: akaberto at gmail.com (akash g) Date: Wed, 13 May 2015 15:23:01 +0530 Subject: [Haskell-beginners] another type problem In-Reply-To: References: <55520761.9080905@home.nl> <555209FB.6000206@home.nl> <55520C7B.5070702@home.nl> <55520DD2.7030908@home.nl> <555211D3.4020805@home.nl> <555316B8.2000408@home.nl> Message-ID: *wrap, not rap. In my previous mail. Also, there is already a library that does list operations in a safe way, though they have used monads. Give a look at the source code and see if it helps. https://hackage.haskell.org/package/listsafe-0.1.0.0/docs/Data-List-Safe.html On Wed, May 13, 2015 at 3:19 PM, akash g wrote: > Ah, but it doesn't. Since this is a functional language, we have a > pointer to it. In fact, all it does is rap it around in the Maybe type. > > Also, my version doesn't do what you want. One way to do that would be > what you have. Or something like this. > > The following turns the partial function in the Prelude to one that is safe > > ========== > import Data.List > > init' :: [a] -> Maybe [a] > init' [] = Nothing -- Base case > init' xs = Just $ tail xs -- Inductive case > ========== > > > > > > > > On Wed, May 13, 2015 at 2:47 PM, Roelof Wobben wrote: > >> Hello, >> >> What my intention was to make a safe version of the init function found >> in Data.list so it procudes a list without the last item. >> At first look your function procudes the whole list again. >> >> Roelof >> >> >> >> akash g schreef op 13-5-2015 om 10:57: >> >> Why not just? >> >> ================== >> init' [] = Nothing >> init' xs = Just xs >> ================== >> >> Meets your type sig and is also has a time complexity of O(1) instead >> of O(n) which will be the time complexity in the solution involving >> fromMaybe. Maybe I'm missing something. >> >> Perhaps it'd help us help you if you'd be a bit more clear on what you >> want to achieve. >> >> On Tue, May 12, 2015 at 9:01 PM, Sumit Sahrawat, Maths & Computing, IIT >> (BHU) wrote: >> >>> On 12 May 2015 at 20:14, Roelof Wobben wrote: >>> >>>> Thanks, >>>> >>>> The right solution was this : >>>> >>>> init' (x:xs) = Just (x:fromMaybe xs (init' xs)) >>>> >>>> if I understand it right x:fromMaybe xs takes care that from xs the >>>> just or Nothing is removed ? >>>> >>>> >>> Trying it out in ghci, >>> >>> fromMaybe [1,2] Nothing == [1,2] >>> fromMaybe [1,2] Just [3] == [3] >>> >>> It seems like that should indeed work. >>> >>> Roelof >>>> >>>> >>>> >>>> Alexey Shmalko schreef op 12-5-2015 om 16:33: >>>> >>>> Try fromMaybe [1]. Examples >>>> >>>> Prelude Data.Maybe> fromMaybe [] (Just [1,2,3]) >>>> [1,2,3] >>>> Prelude Data.Maybe> fromMaybe [1,2,3] Nothing >>>> [1,2,3] >>>> >>>> [1]: >>>> https://hackage.haskell.org/package/base-4.8.0.0/docs/Data-Maybe.html#v:fromMaybe >>>> >>>> On Tue, May 12, 2015 at 5:28 PM Roelof Wobben wrote: >>>> >>>>> Oke, >>>>> >>>>> And how do I do this. Haskell is a difficult one to learn, >>>>> >>>>> Roelof >>>>> >>>>> >>>>> >>>>> Alexey Shmalko schreef op 12-5-2015 om 16:24: >>>>> >>>>> Before cons'ing the result of init', you should check whether it's >>>>> Just or Nothing. What you're doing now is something along the line with 5 : >>>>> Just 3 -- this won't typecheck. >>>>> >>>>> On Tue, May 12, 2015 at 5:22 PM Roelof Wobben >>>>> wrote: >>>>> >>>>>> Brandon Allbery schreef op 12-5-2015 om 16:16: >>>>>> >>>>>> On Tue, May 12, 2015 at 10:11 AM, Roelof Wobben >>>>>> wrote: >>>>>> >>>>>>> I do not understand what you are saying to me. >>>>>>> >>>>>>> I know that init produces a Maybe [a] . That is why I did put a Just >>>>>>> before it. >>>>>>> >>>>>> >>>>>> You are invoking it again though, and using its result as if it >>>>>> produces [a] instead of Maybe [a]. >>>>>> >>>>>> -- >>>>>> brandon s allbery kf8nh sine nomine >>>>>> associates >>>>>> allbery.b at gmail.com >>>>>> ballbery at sinenomine.net >>>>>> unix, openafs, kerberos, infrastructure, xmonad >>>>>> http://sinenomine.net >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>> >>>>>> >>>>>> What is then the right way to do. I still do not understand what >>>>>> you are trying to make clear to me. >>>>>> >>>>>> >>>>>> Roelof >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> ------------------------------ >>>>>> [image: Avast logo] >>>>>> >>>>>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>>>>> antivirussoftware. >>>>>> www.avast.com >>>>>> >>>>>> _______________________________________________ >>>>>> 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 >>>>> >>>>> >>>>> >>>>> >>>>> ------------------------------ >>>>> [image: Avast logo] >>>>> >>>>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>>>> antivirussoftware. >>>>> www.avast.com >>>>> >>>>> _______________________________________________ >>>>> 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 >>>> >>>> >>>> >>>> >>>> ------------------------------ >>>> [image: Avast logo] >>>> >>>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>>> antivirussoftware. >>>> www.avast.com >>>> >>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>>> >>> >>> >>> -- >>> Regards >>> >>> Sumit Sahrawat >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> >> >> _______________________________________________ >> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> >> >> >> ------------------------------ >> [image: Avast logo] >> >> Dit e-mailbericht is gecontroleerd op virussen met Avast >> antivirussoftware. >> www.avast.com >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From akaberto at gmail.com Wed May 13 10:02:12 2015 From: akaberto at gmail.com (akash g) Date: Wed, 13 May 2015 15:32:12 +0530 Subject: [Haskell-beginners] another type problem In-Reply-To: References: <55520761.9080905@home.nl> <555209FB.6000206@home.nl> <55520C7B.5070702@home.nl> <55520DD2.7030908@home.nl> <555211D3.4020805@home.nl> <555316B8.2000408@home.nl> Message-ID: Perhaps a good place to start with functional programming is SICP : http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html#%_toc_start While it doesn't teach you via the Haskell language, it teaches you how to construct functional programs and how the compiler/interpreter views it. Also, it teaches higher order programming quite well, At least, it is much better than every intro haskell book I've read. On Wed, May 13, 2015 at 3:23 PM, akash g wrote: > *wrap, not rap. In my previous mail. > > Also, there is already a library that does list operations in a safe way, > though they have used monads. Give a look at the source code and see if it > helps. > > > https://hackage.haskell.org/package/listsafe-0.1.0.0/docs/Data-List-Safe.html > > > On Wed, May 13, 2015 at 3:19 PM, akash g wrote: > >> Ah, but it doesn't. Since this is a functional language, we have a >> pointer to it. In fact, all it does is rap it around in the Maybe type. >> >> Also, my version doesn't do what you want. One way to do that would be >> what you have. Or something like this. >> >> The following turns the partial function in the Prelude to one that is >> safe >> >> ========== >> import Data.List >> >> init' :: [a] -> Maybe [a] >> init' [] = Nothing -- Base case >> init' xs = Just $ tail xs -- Inductive case >> ========== >> >> >> >> >> >> >> >> On Wed, May 13, 2015 at 2:47 PM, Roelof Wobben wrote: >> >>> Hello, >>> >>> What my intention was to make a safe version of the init function found >>> in Data.list so it procudes a list without the last item. >>> At first look your function procudes the whole list again. >>> >>> Roelof >>> >>> >>> >>> akash g schreef op 13-5-2015 om 10:57: >>> >>> Why not just? >>> >>> ================== >>> init' [] = Nothing >>> init' xs = Just xs >>> ================== >>> >>> Meets your type sig and is also has a time complexity of O(1) instead >>> of O(n) which will be the time complexity in the solution involving >>> fromMaybe. Maybe I'm missing something. >>> >>> Perhaps it'd help us help you if you'd be a bit more clear on what you >>> want to achieve. >>> >>> On Tue, May 12, 2015 at 9:01 PM, Sumit Sahrawat, Maths & Computing, IIT >>> (BHU) wrote: >>> >>>> On 12 May 2015 at 20:14, Roelof Wobben wrote: >>>> >>>>> Thanks, >>>>> >>>>> The right solution was this : >>>>> >>>>> init' (x:xs) = Just (x:fromMaybe xs (init' xs)) >>>>> >>>>> if I understand it right x:fromMaybe xs takes care that from xs the >>>>> just or Nothing is removed ? >>>>> >>>>> >>>> Trying it out in ghci, >>>> >>>> fromMaybe [1,2] Nothing == [1,2] >>>> fromMaybe [1,2] Just [3] == [3] >>>> >>>> It seems like that should indeed work. >>>> >>>> Roelof >>>>> >>>>> >>>>> >>>>> Alexey Shmalko schreef op 12-5-2015 om 16:33: >>>>> >>>>> Try fromMaybe [1]. Examples >>>>> >>>>> Prelude Data.Maybe> fromMaybe [] (Just [1,2,3]) >>>>> [1,2,3] >>>>> Prelude Data.Maybe> fromMaybe [1,2,3] Nothing >>>>> [1,2,3] >>>>> >>>>> [1]: >>>>> https://hackage.haskell.org/package/base-4.8.0.0/docs/Data-Maybe.html#v:fromMaybe >>>>> >>>>> On Tue, May 12, 2015 at 5:28 PM Roelof Wobben >>>>> wrote: >>>>> >>>>>> Oke, >>>>>> >>>>>> And how do I do this. Haskell is a difficult one to learn, >>>>>> >>>>>> Roelof >>>>>> >>>>>> >>>>>> >>>>>> Alexey Shmalko schreef op 12-5-2015 om 16:24: >>>>>> >>>>>> Before cons'ing the result of init', you should check whether it's >>>>>> Just or Nothing. What you're doing now is something along the line with 5 : >>>>>> Just 3 -- this won't typecheck. >>>>>> >>>>>> On Tue, May 12, 2015 at 5:22 PM Roelof Wobben >>>>>> wrote: >>>>>> >>>>>>> Brandon Allbery schreef op 12-5-2015 om 16:16: >>>>>>> >>>>>>> On Tue, May 12, 2015 at 10:11 AM, Roelof Wobben >>>>>>> wrote: >>>>>>> >>>>>>>> I do not understand what you are saying to me. >>>>>>>> >>>>>>>> I know that init produces a Maybe [a] . That is why I did put a >>>>>>>> Just before it. >>>>>>>> >>>>>>> >>>>>>> You are invoking it again though, and using its result as if it >>>>>>> produces [a] instead of Maybe [a]. >>>>>>> >>>>>>> -- >>>>>>> brandon s allbery kf8nh sine nomine >>>>>>> associates >>>>>>> allbery.b at gmail.com >>>>>>> ballbery at sinenomine.net >>>>>>> unix, openafs, kerberos, infrastructure, xmonad >>>>>>> http://sinenomine.net >>>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>>> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>>> >>>>>>> >>>>>>> What is then the right way to do. I still do not understand what >>>>>>> you are trying to make clear to me. >>>>>>> >>>>>>> >>>>>>> Roelof >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> ------------------------------ >>>>>>> [image: Avast logo] >>>>>>> >>>>>>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>>>>>> antivirussoftware. >>>>>>> www.avast.com >>>>>>> >>>>>>> _______________________________________________ >>>>>>> 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 >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> ------------------------------ >>>>>> [image: Avast logo] >>>>>> >>>>>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>>>>> antivirussoftware. >>>>>> www.avast.com >>>>>> >>>>>> _______________________________________________ >>>>>> 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 >>>>> >>>>> >>>>> >>>>> >>>>> ------------------------------ >>>>> [image: Avast logo] >>>>> >>>>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>>>> antivirussoftware. >>>>> www.avast.com >>>>> >>>>> >>>>> _______________________________________________ >>>>> Beginners mailing list >>>>> Beginners at haskell.org >>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>> >>>>> >>>> >>>> >>>> -- >>>> Regards >>>> >>>> Sumit Sahrawat >>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>>> >>> >>> >>> _______________________________________________ >>> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >>> >>> >>> ------------------------------ >>> [image: Avast logo] >>> >>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>> antivirussoftware. >>> www.avast.com >>> >>> >>> _______________________________________________ >>> 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 sumit.sahrawat.apm13 at iitbhu.ac.in Wed May 13 11:32:54 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Wed, 13 May 2015 17:02:54 +0530 Subject: [Haskell-beginners] another type problem In-Reply-To: References: <55520761.9080905@home.nl> <555209FB.6000206@home.nl> <55520C7B.5070702@home.nl> <55520DD2.7030908@home.nl> <555211D3.4020805@home.nl> <555316B8.2000408@home.nl> Message-ID: Init returns all but the last element of a list. The idea behind the recursive solution is to keep accepting elements till there is only one left, and replace it with the empty list. For example, init [1, 2, 3] == init (1 : 2 : 3 : []) { desugar list syntax } == 1 : init (2 : 3 : []) { apply init } == 1 : 2 : init (3 : []) { apply init } == 1 : 2 : [] { init [x] = [] } On 13 May 2015 at 15:32, akash g wrote: > Perhaps a good place to start with functional programming is SICP : > http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html#%_toc_start > > While it doesn't teach you via the Haskell language, it teaches you how to > construct functional programs and how the compiler/interpreter views it. > Also, it teaches higher order programming quite well, At least, it is much > better than every intro haskell book I've read. > > On Wed, May 13, 2015 at 3:23 PM, akash g wrote: > >> *wrap, not rap. In my previous mail. >> >> Also, there is already a library that does list operations in a safe way, >> though they have used monads. Give a look at the source code and see if it >> helps. >> >> >> https://hackage.haskell.org/package/listsafe-0.1.0.0/docs/Data-List-Safe.html >> >> >> On Wed, May 13, 2015 at 3:19 PM, akash g wrote: >> >>> Ah, but it doesn't. Since this is a functional language, we have a >>> pointer to it. In fact, all it does is rap it around in the Maybe type. >>> >>> Also, my version doesn't do what you want. One way to do that would be >>> what you have. Or something like this. >>> >>> The following turns the partial function in the Prelude to one that is >>> safe >>> >>> ========== >>> import Data.List >>> >>> init' :: [a] -> Maybe [a] >>> init' [] = Nothing -- Base case >>> init' xs = Just $ tail xs -- Inductive case >>> ========== >>> >>> >>> >>> >>> >>> >>> >>> On Wed, May 13, 2015 at 2:47 PM, Roelof Wobben wrote: >>> >>>> Hello, >>>> >>>> What my intention was to make a safe version of the init function found >>>> in Data.list so it procudes a list without the last item. >>>> At first look your function procudes the whole list again. >>>> >>>> Roelof >>>> >>>> >>>> >>>> akash g schreef op 13-5-2015 om 10:57: >>>> >>>> Why not just? >>>> >>>> ================== >>>> init' [] = Nothing >>>> init' xs = Just xs >>>> ================== >>>> >>>> Meets your type sig and is also has a time complexity of O(1) instead >>>> of O(n) which will be the time complexity in the solution involving >>>> fromMaybe. Maybe I'm missing something. >>>> >>>> Perhaps it'd help us help you if you'd be a bit more clear on what you >>>> want to achieve. >>>> >>>> On Tue, May 12, 2015 at 9:01 PM, Sumit Sahrawat, Maths & Computing, IIT >>>> (BHU) wrote: >>>> >>>>> On 12 May 2015 at 20:14, Roelof Wobben wrote: >>>>> >>>>>> Thanks, >>>>>> >>>>>> The right solution was this : >>>>>> >>>>>> init' (x:xs) = Just (x:fromMaybe xs (init' xs)) >>>>>> >>>>>> if I understand it right x:fromMaybe xs takes care that from xs the >>>>>> just or Nothing is removed ? >>>>>> >>>>>> >>>>> Trying it out in ghci, >>>>> >>>>> fromMaybe [1,2] Nothing == [1,2] >>>>> fromMaybe [1,2] Just [3] == [3] >>>>> >>>>> It seems like that should indeed work. >>>>> >>>>> Roelof >>>>>> >>>>>> >>>>>> >>>>>> Alexey Shmalko schreef op 12-5-2015 om 16:33: >>>>>> >>>>>> Try fromMaybe [1]. Examples >>>>>> >>>>>> Prelude Data.Maybe> fromMaybe [] (Just [1,2,3]) >>>>>> [1,2,3] >>>>>> Prelude Data.Maybe> fromMaybe [1,2,3] Nothing >>>>>> [1,2,3] >>>>>> >>>>>> [1]: >>>>>> https://hackage.haskell.org/package/base-4.8.0.0/docs/Data-Maybe.html#v:fromMaybe >>>>>> >>>>>> On Tue, May 12, 2015 at 5:28 PM Roelof Wobben >>>>>> wrote: >>>>>> >>>>>>> Oke, >>>>>>> >>>>>>> And how do I do this. Haskell is a difficult one to learn, >>>>>>> >>>>>>> Roelof >>>>>>> >>>>>>> >>>>>>> >>>>>>> Alexey Shmalko schreef op 12-5-2015 om 16:24: >>>>>>> >>>>>>> Before cons'ing the result of init', you should check whether it's >>>>>>> Just or Nothing. What you're doing now is something along the line with 5 : >>>>>>> Just 3 -- this won't typecheck. >>>>>>> >>>>>>> On Tue, May 12, 2015 at 5:22 PM Roelof Wobben >>>>>>> wrote: >>>>>>> >>>>>>>> Brandon Allbery schreef op 12-5-2015 om 16:16: >>>>>>>> >>>>>>>> On Tue, May 12, 2015 at 10:11 AM, Roelof Wobben >>>>>>>> wrote: >>>>>>>> >>>>>>>>> I do not understand what you are saying to me. >>>>>>>>> >>>>>>>>> I know that init produces a Maybe [a] . That is why I did put a >>>>>>>>> Just before it. >>>>>>>>> >>>>>>>> >>>>>>>> You are invoking it again though, and using its result as if it >>>>>>>> produces [a] instead of Maybe [a]. >>>>>>>> >>>>>>>> -- >>>>>>>> brandon s allbery kf8nh sine nomine >>>>>>>> associates >>>>>>>> allbery.b at gmail.com >>>>>>>> ballbery at sinenomine.net >>>>>>>> unix, openafs, kerberos, infrastructure, xmonad >>>>>>>> http://sinenomine.net >>>>>>>> >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>>>> >>>>>>>> >>>>>>>> What is then the right way to do. I still do not understand what >>>>>>>> you are trying to make clear to me. >>>>>>>> >>>>>>>> >>>>>>>> Roelof >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> ------------------------------ >>>>>>>> [image: Avast logo] >>>>>>>> >>>>>>>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>>>>>>> antivirussoftware. >>>>>>>> www.avast.com >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> 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 >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> ------------------------------ >>>>>>> [image: Avast logo] >>>>>>> >>>>>>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>>>>>> antivirussoftware. >>>>>>> www.avast.com >>>>>>> >>>>>>> _______________________________________________ >>>>>>> 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 >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> ------------------------------ >>>>>> [image: Avast logo] >>>>>> >>>>>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>>>>> antivirussoftware. >>>>>> www.avast.com >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> Beginners mailing list >>>>>> Beginners at haskell.org >>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>> >>>>>> >>>>> >>>>> >>>>> -- >>>>> Regards >>>>> >>>>> Sumit Sahrawat >>>>> >>>>> _______________________________________________ >>>>> Beginners mailing list >>>>> Beginners at haskell.org >>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>> >>>>> >>>> >>>> >>>> _______________________________________________ >>>> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>>> >>>> >>>> >>>> ------------------------------ >>>> [image: Avast logo] >>>> >>>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>>> antivirussoftware. >>>> www.avast.com >>>> >>>> >>>> _______________________________________________ >>>> 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 > > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Wed May 13 11:40:50 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Wed, 13 May 2015 17:10:50 +0530 Subject: [Haskell-beginners] Are these solution the Haskell way ? In-Reply-To: <5552FB59.8080702@home.nl> References: <5552EAC9.7060900@home.nl> <5552F1B7.1080708@home.nl> <5552F565.1010907@home.nl> <5552FB59.8080702@home.nl> Message-ID: The evaluation would go the way Frerich shows it. In particular you should know that these two notations are equivalent. [1,2,3] == 1 : 2 : 3 : [] The cons (:) operator (with type a -> [a] -> [a]) adds an element to the start of a list. Also, as it is right associative 1 : 2 : 3 : [] == 1 : (2 : (3 : [])) { right associativity } == 1 : (2 : [3]) { add element to empty list } == 1 : [2, 3] { add element } == [1, 2, 3] { add element } On 13 May 2015 at 12:50, Roelof Wobben wrote: > Hello, > > I see it. > > plusplus [1,2] [3,4] > plusplus [1] : plusplus [2] [3,4] > plusplus [1] : [2] : plusplus [] [3,4] > plusplus [1] : [2] : [3,4] > [1:2:3:4] > > I think I need some more practice on this. > Does anyone know a good exercise ? > > Roelof > > > Daniel P. Wright schreef op 13-5-2015 om 9:08: > > Think about what the possible values of "xs" might be, and trace through > the next call to "plusplus xs ys". > > It would help if I didn't name the variables stupidly... here is a > slightly better version: > > plusplus [] ys = ys > plusplus (x:xs) ys = x : plusplus xs ys > > If it helps, try tracing through the steps required to evaluate > "plusplus [1, 2] [3, 4]" manually (using a pen and paper, not on the > computer) > > 2015-05-13 15:55 GMT+09:00 Roelof Wobben : > >> Thanks, >> >> So the answer is x and the rest of xs and ys. >> How do x then get added to ys. >> >> Roelof >> >> Daniel P. Wright schreef op 13-5-2015 om 8:52: >> >> Ah, that's just a small syntactic issue -- in Haskell, operators are >> infix (go between the arguments) by default, but named functions are not. >> So you would have to write it: >> >> plusplus [] xs = xs >> plusplus (x:xs) ys = x : plusplus xs ys >> >> >> 2015-05-13 15:39 GMT+09:00 Roelof Wobben : >> >>> Thanks, >>> >>> If I re-implement it like this : >>> >>> plusplus :: [a] -> [a] -> [a] >>> plusplus [] (xs) = xs >>> plusplus (x:xs) yx = x : xs plusplus yx >>> >>> main = print $ ["a","b"] plusplus ["c","d"] >>> >>> >>> I see this error appear : >>> >>> src/Main.hs at 3:26-3:40 >>> Couldn't match expected type ?([a0] -> [a0] -> [a0]) -> [a] -> [a]? with >>> actual type >>> [a] >>> Relevant bindings include yx :: [a] (bound at >>> /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:3:17) >>> xs :: [a] (bound at >>> /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:3:13) >>> x :: a (bound at >>> /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:3:11) >>> plusplus :: [a] -> [a] -> [a] (bound at >>> /home/app/isolation-runner-work/projects/112825/session.207/src/src/Main.hs:2:1) >>> The function >>> xs >>> is applied to two arguments, but its type >>> [a] >>> has none ? >>> >>> So for me not a aha moment. I was hoping I would get it >>> >>> Roelof >>> >>> Daniel P. Wright schreef op 13-5-2015 om 8:27: >>> >>> Hi Roelof, >>> >>> If you don't consider it cheating (and I suggest you shouldn't, having >>> had a stab at the answers), you will find great enlightenment looking at >>> how these functions are *actually* implemented in the wild. Did you know >>> that there is a "source" link for each function on Hackage? By clicking on >>> that, for your first example, you can compare the actual implementation of >>> (++) with your "plusplus" function: >>> >>> >>> http://hackage.haskell.org/package/base-4.8.0.0/docs/src/GHC-Base.html#%2B%2B >>> >>> (By the way, it's that function in particular that gave me one of my >>> first "Aha!" moments in Haskell... it's quite beautiful in its simplicity). >>> >>> One thing with viewing the source on Hackage is that sometimes it can >>> be a little more confusing than it needs to be for the sake of efficiency. >>> A really good source for good, readable examples of Prelude functions in >>> Haskell is the Haskell Report: >>> >>> https://www.haskell.org/onlinereport/standard-prelude.html >>> >>> (In this case, though, the implementation is the same). >>> >>> Having a shot at defining these library functions yourself, as you >>> have done, and then comparing your version with the "official" version in >>> the prelude is a great way to learn good style! >>> >>> -Dani. >>> >>> 2015-05-13 15:10 GMT+09:00 Roelof Wobben : >>> >>>> Hello, >>>> >>>> For practising pattern matching and recursion I did recreate some >>>> commands of Data,list. >>>> >>>> My re-implementation of ++ : >>>> >>>> plusplus :: [a] -> [a] -> [a] >>>> plusplus [] [] = [] ; >>>> plusplus [] (xs) = xs >>>> plusplus (xs) [] = xs >>>> plusplus (xs) yx = plusplus' (reverse xs) yx >>>> >>>> plusplus' :: [a] -> [a] -> [a] >>>> plusplus' [] (xs) = xs >>>> plusplus' (x:xs) yx = plusplus' xs (x:yx) >>>> >>>> main = print $ plusplus ["a","b"] ["c","d"] >>>> >>>> my re-implementation of init : >>>> >>>> import Data.Maybe >>>> >>>> -- | The main entry point. >>>> init' :: [a] -> Maybe [a] >>>> init' [] = Nothing >>>> init' [x] = Just [] >>>> init' (x:xs) = Just (x:fromMaybe xs (init' xs)) >>>> >>>> main = print . init' $ [1,3] >>>> >>>> >>>> my re-implementation of last : >>>> >>>> -- | The main entry point. >>>> last' :: [a] -> Maybe a >>>> last' [] = Nothing >>>> last' [x] = Just x >>>> last' (_:xs) = last' xs >>>> >>>> main = print . last' $ [] >>>> >>>> Now I wonder if these solutions are the haskell way ? if not so, how >>>> can I improve them , >>>> >>>> Roelof >>>> >>>> >>>> --- >>>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>>> antivirussoftware. >>>> http://www.avast.com >>>> >>>> _______________________________________________ >>>> 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 >>> >>> >>> >>> >>> ------------------------------ >>> [image: Avast logo] >>> >>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>> antivirussoftware. >>> www.avast.com >>> >>> >>> _______________________________________________ >>> 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 >> >> >> >> >> ------------------------------ >> [image: Avast logo] >> >> Dit e-mailbericht is gecontroleerd op virussen met Avast >> antivirussoftware. >> www.avast.com >> >> >> _______________________________________________ >> 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 > > > > > ------------------------------ > [image: Avast logo] > > Dit e-mailbericht is gecontroleerd op virussen met Avast > antivirussoftware. > www.avast.com > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Wed May 13 11:43:20 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Wed, 13 May 2015 13:43:20 +0200 Subject: [Haskell-beginners] accumenlator problem Message-ID: <555338D8.6080703@home.nl> Hello, I have this : -- | Convert a digit to a list for example 123 becomes [1,2,3] toDigits :: Integer -> [Integer] toDigits number | number <= 0 = [] | number > 0 = toDigitsAcc [] number toDigitsAcc:: [Integer] -> [Integer] -> [Integer] toDigitsAcc acc number | number <= 0 = acc | number > 0 = (number `mod` 10) : acc toDigitsAcc (number `div` 10) bur there are error on both last lines of he functions. Any tips how to solve this ? Roelof --- Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. http://www.avast.com From nishantgeek at gmail.com Wed May 13 12:04:53 2015 From: nishantgeek at gmail.com (Nishant) Date: Wed, 13 May 2015 17:34:53 +0530 Subject: [Haskell-beginners] accumenlator problem In-Reply-To: <555338D8.6080703@home.nl> References: <555338D8.6080703@home.nl> Message-ID: I think you wanted something like this : toDigits :: Integer -> [Integer] toDigits number | number <= 0 = [] | number > 0 = toDigitsAcc [] number --( toDigits (number `div` 10) ) ++ [number `mod` 10] toDigitsAcc:: [Integer] -> Integer -> [Integer] toDigitsAcc acc number | number <= 0 = acc | number > 0 = toDigitsAcc ((number `mod` 10) : acc) (number `div` 10) Regards Nishant Verma On Wed, May 13, 2015 at 5:13 PM, Roelof Wobben wrote: > Hello, > > I have this : > > -- | Convert a digit to a list for example 123 becomes [1,2,3] > toDigits :: Integer -> [Integer] > toDigits number > | number <= 0 = [] > | number > 0 = toDigitsAcc [] number > > toDigitsAcc:: [Integer] -> [Integer] -> [Integer] > toDigitsAcc acc number > | number <= 0 = acc > | number > 0 = (number `mod` 10) : acc toDigitsAcc (number `div` 10) > > bur there are error on both last lines of he functions. > > Any tips how to solve this ? > > Roelof > > > --- > Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. > http://www.avast.com > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Nishant -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Wed May 13 12:11:29 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Wed, 13 May 2015 14:11:29 +0200 Subject: [Haskell-beginners] accumenlator problem In-Reply-To: References: <555338D8.6080703@home.nl> Message-ID: <55533F71.8040308@home.nl> Nishant schreef op 13-5-2015 om 14:04: > number > 0 = toDigitsAcc ((number `mod` 10) : acc) (number `div` 10) Thanks, I now see where my thinking took the wrong way Roelof --- Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. http://www.avast.com From r.wobben at home.nl Wed May 13 16:52:38 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Wed, 13 May 2015 18:52:38 +0200 Subject: [Haskell-beginners] can I have a case statement with a pattern matching Message-ID: <55538156.3000607@home.nl> Hello, I try to make make the assignment of CIS194 where I must multiply every second item from the right by 2 So I thought this could be working : -- | Convert a digit to a reversed list for example 123 becomes [3,2,1] revtoDigits :: Integer -> [Integer] revtoDigits number | number <= 0 = [] | number > 0 = number`mod` 10 : revtoDigits (number `div` 10) -- | Convert a digit to a list for example 123 becomes [1,2,3] toDigits :: Integer -> [Integer] toDigits number | number <= 0 = [] | number > 0 = toDigitsAcc [] number toDigitsAcc:: [Integer] -> Integer -> [Integer] toDigitsAcc acc number | number <= 0 = acc | number > 0 = toDigitsAcc ((number `mod` 10) : acc) (number `div` 10) doubleEveryOther :: [Integer] -> [Integer] doubleEveryOther list = case (length list) `mod` 2 of 0 -> doubleEveryOther [] = [] doubleEveryOther (x:y:xs) = x*2 : y : xs (length list) `mod` 2 of 0 -> doubleEveryOther [] = [] doubleEveryOther (x:y:xs) = x : y*2 : xs -- | The main entry point. main = print $ doubleEveryOther [1,2,3] but apperantly you cannot have pattern matching after a case statement because I get a error on the = of a empty list Roelof --- Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. http://www.avast.com From shishir.srivastava at gmail.com Wed May 13 21:12:21 2015 From: shishir.srivastava at gmail.com (Shishir Srivastava) Date: Wed, 13 May 2015 22:12:21 +0100 Subject: [Haskell-beginners] Function Composition Message-ID: Hi, Could someone please point out what is the difference between using $ and parenthesis in the function composition below. Why does the first expression work whereas the second fails. --- $$ head.head$[[1,2],[3,4]] 1 $$ head.head([[1,2],[3,4]]) :122:12: Couldn't match expected type ?a -> [c]? with actual type ?[t0]? Relevant bindings include --- Thanks, Shishir -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Wed May 13 21:22:43 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Thu, 14 May 2015 02:52:43 +0530 Subject: [Haskell-beginners] Function Composition In-Reply-To: References: Message-ID: Function application has the strongest precedence, thus something like fun1 . fun2 arg is equivalent to fun1 . (fun2 arg) Now, ($) is the same as function application, but has lowest precedence (even lower than (.)). infixr 0 ($) ($) :: (a -> b) -> a -> b f $ x = f x Thus, fun1 . fun2 $ arg is equivalent to (fun1 . fun2) $ arg == (fun1 . fun2) arg { apply ($) } On 14 May 2015 at 02:42, Shishir Srivastava wrote: > Hi, > > Could someone please point out what is the difference between using $ and > parenthesis in the function composition below. Why does the first > expression work whereas the second fails. > --- > $$ head.head$[[1,2],[3,4]] > 1 > $$ head.head([[1,2],[3,4]]) > > :122:12: > Couldn't match expected type ?a -> [c]? with actual type ?[t0]? > Relevant bindings include > --- > Thanks, > Shishir > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From nishantgeek at gmail.com Thu May 14 06:48:37 2015 From: nishantgeek at gmail.com (Nishant) Date: Thu, 14 May 2015 12:18:37 +0530 Subject: [Haskell-beginners] can I have a case statement with a pattern matching In-Reply-To: <55538156.3000607@home.nl> References: <55538156.3000607@home.nl> Message-ID: This will double very second digit in list. To do from right, just reverse the list first and then apply doubleEverySecond and then reverse back. doubleEveryOther :: [Integer] -> [Integer] doubleEveryOther [] = [] doubleEveryOther (x : []) = [x] doubleEveryOther (x : y : []) = x : (2 * y) : [] doubleEveryOther (x:y:xs) = x : (2 * y) : doubleEveryOther (xs) On Wed, May 13, 2015 at 10:22 PM, Roelof Wobben wrote: > Hello, > > I try to make make the assignment of CIS194 where I must multiply every > second item from the right by 2 > > So I thought this could be working : > > -- | Convert a digit to a reversed list for example 123 becomes [3,2,1] > revtoDigits :: Integer -> [Integer] > revtoDigits number > | number <= 0 = [] > | number > 0 = number`mod` 10 : revtoDigits (number `div` 10) > > -- | Convert a digit to a list for example 123 becomes [1,2,3] > toDigits :: Integer -> [Integer] > toDigits number > | number <= 0 = [] > | number > 0 = toDigitsAcc [] number > > toDigitsAcc:: [Integer] -> Integer -> [Integer] > toDigitsAcc acc number > | number <= 0 = acc > | number > 0 = toDigitsAcc ((number `mod` 10) : acc) (number `div` 10) > > doubleEveryOther :: [Integer] -> [Integer] > doubleEveryOther list = case (length list) `mod` 2 of 0 -> > doubleEveryOther [] = [] > doubleEveryOther (x:y:xs) = x*2 : y : xs > (length list) `mod` 2 of 0 -> > doubleEveryOther [] = [] > doubleEveryOther (x:y:xs) = x : y*2 : xs > > > -- | The main entry point. > main = print $ doubleEveryOther [1,2,3] > > > but apperantly you cannot have pattern matching after a case statement > because I get a error on the = of a empty list > > Roelof > > > --- > Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. > http://www.avast.com > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Nishant -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan9131 at gmail.com Thu May 14 07:20:13 2015 From: dan9131 at gmail.com (Dananji Liyanage) Date: Thu, 14 May 2015 12:50:13 +0530 Subject: [Haskell-beginners] Date Time in Haskell Message-ID: Hi All, I'm trying out the date time conversions in Haskell. How do I convert a keyboard input (IO String) to UTCTime? This is how I'm doing (probably there's a better way), convDay x = read (x ++ " 00:00:00") :: UTCTime ?? Another thing, how do I convert getCurrentTime (IO UTCTime) to UTCTime in order to get the time difference between the keyboard input date and today? -- Regards, Dananji Liyanage -------------- next part -------------- An HTML attachment was scrubbed... URL: From k-bx at k-bx.com Thu May 14 10:25:21 2015 From: k-bx at k-bx.com (Kostiantyn Rybnikov) Date: Thu, 14 May 2015 13:25:21 +0300 Subject: [Haskell-beginners] Date Time in Haskell In-Reply-To: References: Message-ID: Hi Dananji! First of all, for more explicit failure-handling I suggest using "readMay" from package "safe" [0] instead of "read" whenever possible. Alternative to using "read", if you know date format of input-data, you can take a look at "UNIX-style parsing" section at Data.Time.Format module [1]. If you have older "time" package, you'd probably use parseTime, for newer versions it is recommended to use parseTimeM. Here's an example: ``` ? ~ ghci GHCi, version 7.8.4: http://www.haskell.org/ghc/ :? for help Prelude> import Data.Time.Format Prelude Data.Time.Format> import System.Locale Prelude Data.Time.Format System.Locale> import Data.Time.Clock Prelude Data.Time.Format System.Locale Data.Time.Clock> parseTime defaultTimeLocale "%F %X" "2014-01-02 11:12:30" :: Maybe UTCTime Just 2014-01-02 11:12:30 UTC ``` If you have a value of type "IO ", you can "extract" it when being in IO monad like this: main = do currentTime <- getCurrentTime -- in all remaining code, currentTime has type "UTCTime" ... getDifference currentTime userTime In terms of "sugar-less" way to use a value from "IO ", you can also use it like this: getCurrentTime >>= \currentTime -> doSomething currentTime Hope this helps. [0]: https://hackage.haskell.org/package/safe [1]: http://hackage.haskell.org/package/time-1.5.0.1/docs/Data-Time-Format.html On Thu, May 14, 2015 at 10:20 AM, Dananji Liyanage wrote: > Hi All, > > I'm trying out the date time conversions in Haskell. > > How do I convert a keyboard input (IO String) to UTCTime? > > This is how I'm doing (probably there's a better way), > convDay x = read (x ++ " 00:00:00") :: UTCTime > ?? > > Another thing, how do I convert getCurrentTime (IO UTCTime) to UTCTime in > order to get the time difference between the keyboard input date and today? > > -- > Regards, > Dananji Liyanage > > _______________________________________________ > 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 dan9131 at gmail.com Thu May 14 10:57:46 2015 From: dan9131 at gmail.com (Dananji Liyanage) Date: Thu, 14 May 2015 16:27:46 +0530 Subject: [Haskell-beginners] Date Time in Haskell In-Reply-To: References: Message-ID: Hi Kostiantyn, Thanks for introducing me to package "Safe" !! main = do currentTime <- getCurrentTime -- in all remaining code, currentTime has type "UTCTime" ... getDifference currentTime userTime This doesn't work for me. Correct me if I'm doing something wrong here. Here's my code: main = do now <- getCurrentTime diffUTCTime now bree bree = readMay "1981-06-16 04:35:25" :: UTCTime This gives an error like this; io.hs:28:5: Couldn't match expected type ?IO b? with actual type ?NominalDiffTime? Relevant bindings include main :: IO b (bound at io.hs:26:1) In a stmt of a 'do' block: diffUTCTime now bree In the expression: do { now <- getCurrentTime; diffUTCTime now bree } On Thu, May 14, 2015 at 3:55 PM, Kostiantyn Rybnikov wrote: > Hi Dananji! > > First of all, for more explicit failure-handling I suggest using "readMay" > from package "safe" [0] instead of "read" whenever possible. > > Alternative to using "read", if you know date format of input-data, you > can take a look at "UNIX-style parsing" section at Data.Time.Format module > [1]. If you have older "time" package, you'd probably use parseTime, for > newer versions it is recommended to use parseTimeM. > > Here's an example: > > ``` > ? ~ ghci > GHCi, version 7.8.4: http://www.haskell.org/ghc/ :? for help > Prelude> import Data.Time.Format > Prelude Data.Time.Format> import System.Locale > Prelude Data.Time.Format System.Locale> import Data.Time.Clock > Prelude Data.Time.Format System.Locale Data.Time.Clock> parseTime > defaultTimeLocale "%F %X" "2014-01-02 11:12:30" :: Maybe UTCTime > Just 2014-01-02 11:12:30 UTC > ``` > > If you have a value of type "IO ", you can "extract" it when > being in IO monad like this: > > main = do > currentTime <- getCurrentTime > -- in all remaining code, currentTime has type "UTCTime" > ... > getDifference currentTime userTime > > In terms of "sugar-less" way to use a value from "IO ", you can > also use it like this: > > getCurrentTime >>= \currentTime -> doSomething currentTime > > Hope this helps. > > [0]: https://hackage.haskell.org/package/safe > [1]: > http://hackage.haskell.org/package/time-1.5.0.1/docs/Data-Time-Format.html > > > On Thu, May 14, 2015 at 10:20 AM, Dananji Liyanage > wrote: > >> Hi All, >> >> I'm trying out the date time conversions in Haskell. >> >> How do I convert a keyboard input (IO String) to UTCTime? >> >> This is how I'm doing (probably there's a better way), >> convDay x = read (x ++ " 00:00:00") :: UTCTime >> ?? >> >> Another thing, how do I convert getCurrentTime (IO UTCTime) to UTCTime in >> order to get the time difference between the keyboard input date and today? >> >> -- >> Regards, >> Dananji Liyanage >> >> _______________________________________________ >> 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 > > -- Regards, Dananji Liyanage -------------- next part -------------- An HTML attachment was scrubbed... URL: From max.voit+mlhb at with-eyes.net Thu May 14 11:27:49 2015 From: max.voit+mlhb at with-eyes.net (Max Voit) Date: Thu, 14 May 2015 13:27:49 +0200 Subject: [Haskell-beginners] Date Time in Haskell In-Reply-To: References: Message-ID: <20150514132749.5f4bea88@veeloqu.lan> On Thu, 14 May 2015 16:27:46 +0530 Dananji Liyanage wrote: > Correct me if I'm doing something wrong here. Here's my code: > > main = do > now <- getCurrentTime > diffUTCTime now bree > bree = readMay "1981-06-16 04:35:25" :: UTCTime There are several problems with that code. First what the compiler is complaining about: Last statement in a do-block must have type of the block, in this case IO () - so print it or return () For the readMay - this is expected to return Maybe UTCTime. To stuff this into diffUTCTime you need to get it out of the Maybe. For my formulation "is expected to" - it won't, as UTCTime has no Read instance (so you can't call read on it). Take a look at ParseTime and its buildTime method. cheers, max From dan9131 at gmail.com Thu May 14 11:54:26 2015 From: dan9131 at gmail.com (Dananji Liyanage) Date: Thu, 14 May 2015 17:24:26 +0530 Subject: [Haskell-beginners] Date Time in Haskell In-Reply-To: <20150514132749.5f4bea88@veeloqu.lan> References: <20150514132749.5f4bea88@veeloqu.lan> Message-ID: Thanks Max!! On Thu, May 14, 2015 at 4:57 PM, Max Voit wrote: > On Thu, 14 May 2015 16:27:46 +0530 > Dananji Liyanage wrote: > > > Correct me if I'm doing something wrong here. Here's my code: > > > > main = do > > now <- getCurrentTime > > diffUTCTime now bree > > bree = readMay "1981-06-16 04:35:25" :: UTCTime > > There are several problems with that code. First what the compiler is > complaining about: Last statement in a do-block must have type of the > block, in this case IO () - so print it or return () > > For the readMay - this is expected to return Maybe UTCTime. To stuff > this into diffUTCTime you need to get it out of the Maybe. > > For my formulation "is expected to" - it won't, as UTCTime has no Read > instance (so you can't call read on it). Take a look at ParseTime and > its buildTime method. > > cheers, max > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Regards, Dananji Liyanage -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael at orlitzky.com Thu May 14 15:23:08 2015 From: michael at orlitzky.com (Michael Orlitzky) Date: Thu, 14 May 2015 11:23:08 -0400 Subject: [Haskell-beginners] Date Time in Haskell In-Reply-To: References: Message-ID: <5554BDDC.7000102@orlitzky.com> On 05/14/2015 06:25 AM, Kostiantyn Rybnikov wrote: > Hi Dananji! > > First of all, for more explicit failure-handling I suggest using "readMay" > from package "safe" [0] instead of "read" whenever possible. This is always a good idea, and someone finally added it to the base library (in 4.6.0.0) as "readMaybe". ghci> import Text.Read ( readMaybe ) ghci> readMaybe "Hello, world!" :: Maybe Integer Nothing From jonathan.skarstedt at gmail.com Thu May 14 16:27:57 2015 From: jonathan.skarstedt at gmail.com (=?UTF-8?Q?Jonathan_Sk=C3=A5rstedt?=) Date: Thu, 14 May 2015 18:27:57 +0200 Subject: [Haskell-beginners] can I have a case statement with a pattern matching In-Reply-To: References: <55538156.3000607@home.nl> Message-ID: I'm nitpicking here, but it can be improved a bit doubleEveryOther :: [Integer] -> [Integer] doubleEveryOther [] = [] doubleEveryOther [x] = [x] doubleEveryOther (x:y:xs) = x : 2 * y : doubleEveryOther (xs) 2015-05-14 8:48 GMT+02:00 Nishant : > This will double very second digit in list. To do from right, just > reverse the list first and then apply doubleEverySecond and then reverse > back. > > > > doubleEveryOther :: [Integer] -> [Integer] > > doubleEveryOther [] = [] > doubleEveryOther (x : []) = [x] > doubleEveryOther (x : y : []) = x : (2 * y) : [] > doubleEveryOther (x:y:xs) = x : (2 * y) : doubleEveryOther (xs) > > > On Wed, May 13, 2015 at 10:22 PM, Roelof Wobben wrote: > >> Hello, >> >> I try to make make the assignment of CIS194 where I must multiply every >> second item from the right by 2 >> >> So I thought this could be working : >> >> -- | Convert a digit to a reversed list for example 123 becomes [3,2,1] >> revtoDigits :: Integer -> [Integer] >> revtoDigits number >> | number <= 0 = [] >> | number > 0 = number`mod` 10 : revtoDigits (number `div` 10) >> >> -- | Convert a digit to a list for example 123 becomes [1,2,3] >> toDigits :: Integer -> [Integer] >> toDigits number >> | number <= 0 = [] >> | number > 0 = toDigitsAcc [] number >> >> toDigitsAcc:: [Integer] -> Integer -> [Integer] >> toDigitsAcc acc number >> | number <= 0 = acc >> | number > 0 = toDigitsAcc ((number `mod` 10) : acc) (number `div` 10) >> >> doubleEveryOther :: [Integer] -> [Integer] >> doubleEveryOther list = case (length list) `mod` 2 of 0 -> >> doubleEveryOther [] = [] >> doubleEveryOther (x:y:xs) = x*2 : y : xs >> (length list) `mod` 2 of 0 -> >> doubleEveryOther [] = [] >> doubleEveryOther (x:y:xs) = x : y*2 : xs >> >> >> -- | The main entry point. >> main = print $ doubleEveryOther [1,2,3] >> >> >> but apperantly you cannot have pattern matching after a case statement >> because I get a error on the = of a empty list >> >> Roelof >> >> >> --- >> Dit e-mailbericht is gecontroleerd op virussen met Avast >> antivirussoftware. >> http://www.avast.com >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > > > -- > Nishant > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Jonathan Sk?rstedt Bergsg?rdsg?rdet 39 Lgh 1108 424 32 G?teborg Mobil: 073 - 76 20 20 7 -------------- next part -------------- An HTML attachment was scrubbed... URL: From rasen.dubi at gmail.com Thu May 14 16:46:48 2015 From: rasen.dubi at gmail.com (Alexey Shmalko) Date: Thu, 14 May 2015 16:46:48 +0000 Subject: [Haskell-beginners] can I have a case statement with a pattern matching In-Reply-To: References: <55538156.3000607@home.nl> Message-ID: Then it could be: doubleEveryOther :: [Integer] -> [Integer] doubleEveryOther (x:y:xs) = x : 2 * y : doubleEveryOther xs doubleEveryOther x = x It could also be generalized to Num's ;) On Thu, May 14, 2015 at 7:28 PM Jonathan Sk?rstedt < jonathan.skarstedt at gmail.com> wrote: > I'm nitpicking here, but it can be improved a bit > > doubleEveryOther :: [Integer] -> [Integer] > doubleEveryOther [] = [] > doubleEveryOther [x] = [x] > doubleEveryOther (x:y:xs) = x : 2 * y : doubleEveryOther (xs) > > 2015-05-14 8:48 GMT+02:00 Nishant : > >> This will double very second digit in list. To do from right, just >> reverse the list first and then apply doubleEverySecond and then reverse >> back. >> >> >> >> doubleEveryOther :: [Integer] -> [Integer] >> >> doubleEveryOther [] = [] >> doubleEveryOther (x : []) = [x] >> doubleEveryOther (x : y : []) = x : (2 * y) : [] >> doubleEveryOther (x:y:xs) = x : (2 * y) : doubleEveryOther (xs) >> >> >> On Wed, May 13, 2015 at 10:22 PM, Roelof Wobben wrote: >> >>> Hello, >>> >>> I try to make make the assignment of CIS194 where I must multiply every >>> second item from the right by 2 >>> >>> So I thought this could be working : >>> >>> -- | Convert a digit to a reversed list for example 123 becomes [3,2,1] >>> revtoDigits :: Integer -> [Integer] >>> revtoDigits number >>> | number <= 0 = [] >>> | number > 0 = number`mod` 10 : revtoDigits (number `div` 10) >>> >>> -- | Convert a digit to a list for example 123 becomes [1,2,3] >>> toDigits :: Integer -> [Integer] >>> toDigits number >>> | number <= 0 = [] >>> | number > 0 = toDigitsAcc [] number >>> >>> toDigitsAcc:: [Integer] -> Integer -> [Integer] >>> toDigitsAcc acc number >>> | number <= 0 = acc >>> | number > 0 = toDigitsAcc ((number `mod` 10) : acc) (number `div` 10) >>> >>> doubleEveryOther :: [Integer] -> [Integer] >>> doubleEveryOther list = case (length list) `mod` 2 of 0 -> >>> doubleEveryOther [] = [] >>> doubleEveryOther (x:y:xs) = x*2 : y : xs >>> (length list) `mod` 2 of 0 -> >>> doubleEveryOther [] = [] >>> doubleEveryOther (x:y:xs) = x : y*2 : xs >>> >>> >>> -- | The main entry point. >>> main = print $ doubleEveryOther [1,2,3] >>> >>> >>> but apperantly you cannot have pattern matching after a case statement >>> because I get a error on the = of a empty list >>> >>> Roelof >>> >>> >>> --- >>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>> antivirussoftware. >>> http://www.avast.com >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >> >> >> >> -- >> Nishant >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > > -- > Jonathan Sk?rstedt > Bergsg?rdsg?rdet 39 > Lgh 1108 > 424 32 G?teborg > Mobil: 073 - 76 20 20 7 > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Thu May 14 21:14:54 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Thu, 14 May 2015 23:14:54 +0200 Subject: [Haskell-beginners] cabal problem Message-ID: <5555104E.3020300@home.nl> Hello,, I want to use the module Digits which according to Hoogle is in Data.Digits But when I do cabal install Data.Digits I see this error message : cabal install Data.Digits cabal: The file does not exist 'Data.Digits' What do I do wrong ? Roelof --- Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. http://www.avast.com From ahammel87 at gmail.com Thu May 14 21:25:27 2015 From: ahammel87 at gmail.com (Alex Hammel) Date: Thu, 14 May 2015 21:25:27 +0000 Subject: [Haskell-beginners] cabal problem In-Reply-To: <5555104E.3020300@home.nl> References: <5555104E.3020300@home.nl> Message-ID: `Data.Digits` is the name of the module. The name of the package is `digits`. Therefore: $(cabal install digits) `cabal` installs packages, which may contain many modules On Thu, 14 May 2015 at 14:14 Roelof Wobben wrote: > Hello,, > > I want to use the module Digits which according to Hoogle is in Data.Digits > > But when I do cabal install Data.Digits I see this error message : > > cabal install Data.Digits > cabal: The file does not exist 'Data.Digits' > > What do I do wrong ? > > Roelof > > > --- > Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. > http://www.avast.com > > _______________________________________________ > 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 letiziagalli.wise at gmail.com Thu May 14 21:32:34 2015 From: letiziagalli.wise at gmail.com (Letizia Galli) Date: Thu, 14 May 2015 23:32:34 +0200 Subject: [Haskell-beginners] CANCEL ME PLEASE Message-ID: -- Letizia Galli 0039 328 6917393 www.letiziagalli.it -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Fri May 15 07:08:25 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Fri, 15 May 2015 09:08:25 +0200 Subject: [Haskell-beginners] cabal problem In-Reply-To: References: <5555104E.3020300@home.nl> Message-ID: <55559B69.7020401@home.nl> An HTML attachment was scrubbed... URL: From r.wobben at home.nl Fri May 15 07:10:15 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Fri, 15 May 2015 09:10:15 +0200 Subject: [Haskell-beginners] cabal problem In-Reply-To: <55559B69.7020401@home.nl> References: <5555104E.3020300@home.nl> <55559B69.7020401@home.nl> Message-ID: <55559BD7.5000706@home.nl> An HTML attachment was scrubbed... URL: From mwm at mired.org Fri May 15 07:19:06 2015 From: mwm at mired.org (Mike Meyer) Date: Fri, 15 May 2015 02:19:06 -0500 Subject: [Haskell-beginners] Questions about optparse-applicative Message-ID: In trying to convert eddie (http://hackage.haskell.org/package/eddie) from CmdArgs optparse-applicative, I've run into a couple of problems. First question: I have options whose legality depends on other options: two that can't be specified together, and a couple that require one of the two, among other things. Is there some way to specify such constraints when building the parser? Maybe a way to print just the usage message if I check these myself? Maybe a better approach? It looks like if I replace main in test/Example/Hello.hs with: main = handleParseResult . Failure $ parserFailure (prefs idm) (info sample briefDesc) ShowHelpText mempty I should just get the Usage message output, but instead I get the full help text. Second, and possibly related, it's not at all clear what fullDesc does in that example program. In particular, removing it doesn't seem to change the program behavior. Is there some behavior I've missed, or is this an error? -------------- next part -------------- An HTML attachment was scrubbed... URL: From Spam at gettingsharper.de Fri May 15 07:31:22 2015 From: Spam at gettingsharper.de (=?windows-1252?Q?Carsten_K=F6nig?=) Date: Fri, 15 May 2015 09:31:22 +0200 Subject: [Haskell-beginners] cabal problem In-Reply-To: <55559BD7.5000706@home.nl> References: <5555104E.3020300@home.nl> <55559B69.7020401@home.nl> <55559BD7.5000706@home.nl> Message-ID: <5555A0CA.1070203@gettingsharper.de> You most likely updated GHC or something and so you have to reinstall all the packages you get errors for first: cabal install QuckCheck -reinstall --force-reinstalls Am 15.05.2015 um 09:10 schrieb Roelof Wobben: > Another problem. > > I now see this output : > > Preprocessing library digits-0.2... > [1 of 1] Compiling Data.Digits ( src/Data/Digits.hs, dist/build/Data/Digits.o ) > /usr/bin/ld: cannot find -lHSQuickCheck-2.8.1-ghc7.8.3 > /usr/bin/ld: cannot find -lHStf-random-0.5-ghc7.8.3 > /usr/bin/ld: cannot find -lHSprimitive-0.6-ghc7.8.3 > /usr/bin/ld: cannot find -lHStransformers-0.4.3.0-ghc7.8.3 > /usr/bin/ld: cannot find -lHSrandom-1.1-ghc7.8.3 > collect2: error: ld returned 1 exit status > Failed to install digits-0.2 > cabal: Error: some packages failed to install: > digits-0.2 failed during the building phase. The exception was: > ExitFailure 1 > codio at switch-grille:~/workspace$ ghc > ghc: no input files > Usage: For basic information, try the `--help' option. > codio at switch-grille:~/workspace$ ghc --version > The Glorious Glasgow Haskell Compilation System, version 7.8.3 > > Roelof > > > > > Roelof Wobben schreef op 15-5-2015 om 9:08: >> Thanks, >> >> And if I want to import it into my project , do I then do import >> Data.Digits ? >> >> Roelof >> >> >> Alex Hammel schreef op 14-5-2015 om 23:25: >>> `Data.Digits` is the name of the module. The name of the package is >>> `digits`. Therefore: $(cabal install digits) >>> >>> `cabal` installs packages, which may contain many modules >>> >>> On Thu, 14 May 2015 at 14:14 Roelof Wobben >> > wrote: >>> >>> Hello,, >>> >>> I want to use the module Digits which according to Hoogle is in >>> Data.Digits >>> >>> But when I do cabal install Data.Digits I see this error message : >>> >>> cabal install Data.Digits >>> cabal: The file does not exist 'Data.Digits' >>> >>> What do I do wrong ? >>> >>> Roelof >>> >>> >>> --- >>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>> antivirussoftware. >>> http://www.avast.com >>> >>> _______________________________________________ >>> 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 >> >> >> >> ------------------------------------------------------------------------ >> Avast logo >> >> Dit e-mailbericht is gecontroleerd op virussen met Avast >> antivirussoftware. >> www.avast.com >> >> >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > ------------------------------------------------------------------------ > Avast logo > > Dit e-mailbericht is gecontroleerd op virussen met Avast > antivirussoftware. > www.avast.com > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Fri May 15 07:42:01 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Fri, 15 May 2015 09:42:01 +0200 Subject: [Haskell-beginners] cabal problem In-Reply-To: <5555A0CA.1070203@gettingsharper.de> References: <5555104E.3020300@home.nl> <55559B69.7020401@home.nl> <55559BD7.5000706@home.nl> <5555A0CA.1070203@gettingsharper.de> Message-ID: <5555A349.1020705@home.nl> An HTML attachment was scrubbed... URL: From Spam at gettingsharper.de Fri May 15 07:45:14 2015 From: Spam at gettingsharper.de (=?windows-1252?Q?Carsten_K=F6nig?=) Date: Fri, 15 May 2015 09:45:14 +0200 Subject: [Haskell-beginners] cabal problem In-Reply-To: <5555A349.1020705@home.nl> References: <5555104E.3020300@home.nl> <55559B69.7020401@home.nl> <55559BD7.5000706@home.nl> <5555A0CA.1070203@gettingsharper.de> <5555A349.1020705@home.nl> Message-ID: <5555A40A.4020703@gettingsharper.de> I think almost any Linux distro would do - but still: try to reinstall those - if it seems to much work you could also deinstall/reinstall Haskell Plattform (I guess this is what you are using) PS: sorry for the type - it should have been "QuickCheck" of course Am 15.05.2015 um 09:42 schrieb Roelof Wobben: > Hello, > > I did not updated GHC because I use the IDe of a cloud provider codio.com > > I think more and more to switch to a linux distro. > > Do you experts have recommendations ? > > Roelof > > > > Carsten K?nig schreef op 15-5-2015 om 9:31: >> You most likely updated GHC or something and so you have to reinstall >> all the packages you get errors for first: >> >> cabal install QuckCheck -reinstall --force-reinstalls >> >> Am 15.05.2015 um 09:10 schrieb Roelof Wobben: >>> Another problem. >>> >>> I now see this output : >>> >>> Preprocessing library digits-0.2... >>> [1 of 1] Compiling Data.Digits ( src/Data/Digits.hs, dist/build/Data/Digits.o ) >>> /usr/bin/ld: cannot find -lHSQuickCheck-2.8.1-ghc7.8.3 >>> /usr/bin/ld: cannot find -lHStf-random-0.5-ghc7.8.3 >>> /usr/bin/ld: cannot find -lHSprimitive-0.6-ghc7.8.3 >>> /usr/bin/ld: cannot find -lHStransformers-0.4.3.0-ghc7.8.3 >>> /usr/bin/ld: cannot find -lHSrandom-1.1-ghc7.8.3 >>> collect2: error: ld returned 1 exit status >>> Failed to install digits-0.2 >>> cabal: Error: some packages failed to install: >>> digits-0.2 failed during the building phase. The exception was: >>> ExitFailure 1 >>> codio at switch-grille:~/workspace$ ghc >>> ghc: no input files >>> Usage: For basic information, try the `--help' option. >>> codio at switch-grille:~/workspace$ ghc --version >>> The Glorious Glasgow Haskell Compilation System, version 7.8.3 >>> >>> Roelof >>> >>> >>> >>> >>> Roelof Wobben schreef op 15-5-2015 om 9:08: >>>> Thanks, >>>> >>>> And if I want to import it into my project , do I then do import >>>> Data.Digits ? >>>> >>>> Roelof >>>> >>>> >>>> Alex Hammel schreef op 14-5-2015 om 23:25: >>>>> `Data.Digits` is the name of the module. The name of the package >>>>> is `digits`. Therefore: $(cabal install digits) >>>>> >>>>> `cabal` installs packages, which may contain many modules >>>>> >>>>> On Thu, 14 May 2015 at 14:14 Roelof Wobben >>>> > wrote: >>>>> >>>>> Hello,, >>>>> >>>>> I want to use the module Digits which according to Hoogle is >>>>> in Data.Digits >>>>> >>>>> But when I do cabal install Data.Digits I see this error message : >>>>> >>>>> cabal install Data.Digits >>>>> cabal: The file does not exist 'Data.Digits' >>>>> >>>>> What do I do wrong ? >>>>> >>>>> Roelof >>>>> >>>>> >>>>> --- >>>>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>>>> antivirussoftware. >>>>> http://www.avast.com >>>>> >>>>> _______________________________________________ >>>>> 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 >>>> >>>> >>>> >>>> ------------------------------------------------------------------------ >>>> Avast logo >>>> >>>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>>> antivirussoftware. >>>> www.avast.com >>>> >>>> >>>> >>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >>> >>> ------------------------------------------------------------------------ >>> Avast logo >>> >>> Dit e-mailbericht is gecontroleerd op virussen met Avast >>> antivirussoftware. >>> www.avast.com >>> >>> >>> >>> >>> _______________________________________________ >>> 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 > > > > ------------------------------------------------------------------------ > Avast logo > > Dit e-mailbericht is gecontroleerd op virussen met Avast > antivirussoftware. > www.avast.com > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From hjgtuyl at chello.nl Fri May 15 08:52:48 2015 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Fri, 15 May 2015 10:52:48 +0200 Subject: [Haskell-beginners] CANCEL ME PLEASE In-Reply-To: References: Message-ID: I don't know if an admin will unsubscribe you, but you can do it yourself at th bottom of the page https://mail.haskell.org/mailman/listinfo/beginners Regards, Henk-Jan van Tuyl -- Folding at home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming -- From nishantgeek at gmail.com Fri May 15 09:48:32 2015 From: nishantgeek at gmail.com (Nishant) Date: Fri, 15 May 2015 15:18:32 +0530 Subject: [Haskell-beginners] Error while using type and data constructor Message-ID: Hi, I was writing some code for Tree. 1 : data Tree a = NULL | Node a (Tree a) (Tree a) works fine. But, 2 : data Tree a = NULL | Tree a (Node a) Tree a does not work. GHCI says Not in scope " type constructor or class 'Node'. Why is 2 declaration not valid though second definition looks much more closer to what a binary tree actually means ? Regards Nishant Verma -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwm at mired.org Fri May 15 10:27:57 2015 From: mwm at mired.org (Mike Meyer) Date: Fri, 15 May 2015 05:27:57 -0500 Subject: [Haskell-beginners] Error while using type and data constructor In-Reply-To: References: Message-ID: On Fri, May 15, 2015 at 4:48 AM, Nishant wrote: > 1 : data Tree a = NULL | Node a (Tree a) (Tree a) works fine. But, > 2 : data Tree a = NULL | Tree a (Node a) Tree a does not work. GHCI says > Not in scope " type constructor or class 'Node'. > > Why is 2 declaration not valid though second definition looks much more > closer to what a binary tree actually means ? > Because Haskell isn't english. A constructor is parsed as the name of the constructor being defined followed by zero or more types. Your first version defines the constructor name Node followed by the types a, Tree a and Tree a. The second one defines the constructor name Tree followed by the types a, Node a and Tree a. You have to define the type Node for this to work. So you could do: data Node a = Node a data Tree a = NULL | Tree (Tree a) (Node a) (Tree a) But then you have to say "Tree NULL (Node 1.0) NULL" to a tree holding 1.0 with empty left and right subtrees. If you do it they way you said first, you can just say "Node 1.0 Null Null". Maybe you want "date Tree a = NULL | Node (Tree a) a (Tree a)"? Then you you can say "Node NULL 1.0 NULL". Or even "Date Tree a = NULL | Tree (Tree a) a (Tree a)", for "Tree NULL 1.0 NULL"? -------------- next part -------------- An HTML attachment was scrubbed... URL: From nishantgeek at gmail.com Fri May 15 10:57:23 2015 From: nishantgeek at gmail.com (Nishant) Date: Fri, 15 May 2015 16:27:23 +0530 Subject: [Haskell-beginners] Error while using type and data constructor In-Reply-To: References: Message-ID: Thanks Mike. The statement " A constructor is parsed as the name of the constructor being defined followed by zero or more types" made everything clear. On Fri, May 15, 2015 at 3:57 PM, Mike Meyer wrote: > On Fri, May 15, 2015 at 4:48 AM, Nishant wrote: > >> 1 : data Tree a = NULL | Node a (Tree a) (Tree a) works fine. But, >> 2 : data Tree a = NULL | Tree a (Node a) Tree a does not work. GHCI says >> Not in scope " type constructor or class 'Node'. >> >> Why is 2 declaration not valid though second definition looks much more >> closer to what a binary tree actually means ? >> > > Because Haskell isn't english. A constructor is parsed as the name of the > constructor being defined followed by zero or more types. Your first > version defines the constructor name Node followed by the types a, Tree a > and Tree a. The second one defines the constructor name Tree followed by > the types a, Node a and Tree a. You have to define the type Node for this > to work. > > So you could do: > > data Node a = Node a > data Tree a = NULL | Tree (Tree a) (Node a) (Tree a) > > But then you have to say "Tree NULL (Node 1.0) NULL" to a tree holding 1.0 > with empty left and right subtrees. If you do it they way you said first, > you can just say "Node 1.0 Null Null". > > Maybe you want "date Tree a = NULL | Node (Tree a) a (Tree a)"? Then you > you can say "Node NULL 1.0 NULL". Or even "Date Tree a = NULL | Tree (Tree > a) a (Tree a)", for "Tree NULL 1.0 NULL"? > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Nishant -------------- next part -------------- An HTML attachment was scrubbed... URL: From eduardo at accountant.com Fri May 15 13:20:43 2015 From: eduardo at accountant.com (Eduardo) Date: Fri, 15 May 2015 13:20:43 +0000 (UTC) Subject: [Haskell-beginners] Haskell data generics Message-ID: Hello everyone, Here is what I am trying to do: using Data and Typeable generate a representation of any datatype. After looking at some examples this was my attempt: http://lpaste.net/132669. But I can't seem to understand how extQ should work. For instance https://github.com/faylang/fay/blob/master/src/Fay/Convert.hs#L54 https://github.com/lymar/hastache/blob/master/Text/Hastache/Context.hs#L321 All seem to use extQ to "choose" the right way to encode the values(I imagine it's because of the cast inside extQ?). So what am I missing here? From hsyl20 at gmail.com Sat May 16 00:52:39 2015 From: hsyl20 at gmail.com (Sylvain Henry) Date: Sat, 16 May 2015 02:52:39 +0200 Subject: [Haskell-beginners] Building glib In-Reply-To: References: Message-ID: Hi, You should try to build with GHC 7.10 (and the last cabal-install too). Sylvain 2015-05-06 18:05 GMT+02:00 C W Rose : > I've been trying to build the glib package (pretty much any version) for > a few days now, with no success. The sequence of results is: > > =================================================================== > cwr at sixpence cabal $ cabal --verbose --global > --package-db=/opt/cabal/package.conf.d install glib-0.12.5.4 > '/opt/cabal/bin/alex' '--version' > '/opt/cabal/bin/cpphs' '--version' > '/usr/bin/gcc' '-dumpversion' > '/opt/cabal/bin/haddock' '--version' > '/opt/cabal/bin/happy' '--version' > '/usr/bin/hpc' 'version' > looking for tool hsc2hs near compiler in /usr/bin > found hsc2hs in /usr/bin/hsc2hs > '/usr/bin/hsc2hs' '--version' > '/opt/cabal/bin/HsColour' '-version' > '/usr/bin/ghc' '-c' '/tmp/6826.c' '-o' '/tmp/6826.o' > '/usr/bin/ld' '-x' '-r' '/tmp/6826.o' '-o' '/tmp/6827.o' > '/usr/bin/pkg-config' '--version' > '/bin/tar' '--help' > Reading available packages... > Warning: The package list for 'hackage.haskell.org' is 52.1 days old. > Run 'cabal update' to get the latest list of available packages. > Choosing modular solver. > Resolving dependencies... > Ready to install glib-0.12.5.4 > Waiting for install task to finish... > Extracting > /opt/cabal/packages/hackage.haskell.org/glib/0.12.5.4/glib-0.12.5.4.tar.gz > to > /tmp/glib-0.12.5.4-6826... > Updating glib.cabal with the latest revision from the index. > creating /tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist/setup > creating /tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist > creating /tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist/setup > copy /tmp/glib-0.12.5.4-6826/glib-0.12.5.4/Setup.hs to > /tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist/setup/setup.hs > '/usr/bin/ghc' '--make' '-odir' > '/tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist/setup' '-hidir' > '/tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist/setup' '-i' > '-i/tmp/glib-0.12.5.4-6826/glib-0.12.5.4' '-package-db' > '/opt/cabal/package.conf.d' '-package-id' > 'Cabal-1.22.1.1-98c5a01d59dd973fd7113dbb82e82560' > '/tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist/setup/setup.hs' '-o' > '/tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist/setup/setup' '-threaded' > [1 of 2] Compiling SetupWrapper ( > /tmp/glib-0.12.5.4-6826/glib-0.12.5.4/SetupWrapper.hs, > /tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist/setup/SetupWrapper.o ) > > /tmp/glib-0.12.5.4-6826/glib-0.12.5.4/SetupWrapper.hs:118:28: Warning: > In the use of `configCompiler' > (imported from Distribution.Simple.Configure): > Deprecated: "'configCompiler' is deprecated. Use 'configCompilerEx' > instead." > [2 of 2] Compiling Main ( > /tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist/setup/setup.hs, > /tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist/setup/Main.o ) > Linking /tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist/setup/setup ... > /tmp/glib-0.12.5.4-6826/glib-0.12.5.4/dist/setup/setup configure > --verbose=2 > --ghc --prefix=/opt/cabal --bindir=/opt/cabal/bin --libdir=/opt/cabal/lib > --libsubdir=glib-0.12.5.4/ghc-7.6.3 --libexecdir=/opt/cabal/libexec > --datadir=/opt/cabal/share --datasubdir=glib-0.12.5.4 > --docdir=/opt/cabal/share/doc/glib-0.12.5.4 > --htmldir=/opt/cabal/share/doc/glib-0.12.5.4/html > --haddockdir=/opt/cabal/share/doc/glib-0.12.5.4/html > --sysconfdir=/opt/cabal/etc --enable-library-profiling > --enable-optimization=2 > --global --package-db=/opt/cabal/package.conf.d --flags=closure_signals > --dependency=utf8-string=utf8-string-0.3.8-51169ff3d90963aa54c0a13eee5c3a53 > --dependency=containers=containers-0.5.0.0-e7e1a93d7945e93a00ce12660e9ff290 > --dependency=base=base-4.6.0.1-220b875e77822b0e1bf50c8f35d37dff > --disable-tests --exact-configuration --disable-benchmarks > [1 of 2] Compiling Gtk2HsSetup ( Gtk2HsSetup.hs, > dist/setup-wrapper/Gtk2HsSetup.o ) > [2 of 2] Compiling Main ( SetupMain.hs, > dist/setup-wrapper/Main.o ) > Linking dist/setup-wrapper/setup ... > unrecognized option `--sysconfdir=/opt/cabal/etc' > > unrecognized option > > `--dependency=utf8-string=utf8-string-0.3.8-51169ff3d90963aa54c0a13eee5c3a53' > > unrecognized option > > `--dependency=containers=containers-0.5.0.0-e7e1a93d7945e93a00ce12660e9ff290' > > unrecognized option > `--dependency=base=base-4.6.0.1-220b875e77822b0e1bf50c8f35d37dff' > > unrecognized option `--exact-configuration' > Failed to install glib-0.12.5.4 > World file is already up to date. > cabal: Error: some packages failed to install: > glib-0.12.5.4 failed during the configure step. The exception was: > ExitFailure 1 > cwr at sixpence cabal $ > =================================================================== > > Moving to the default version of glib, I then get: > > =================================================================== > cwr at sixpence cabal $ cabal --verbose --global > --package-db=/opt/cabal/package.conf.d install glib > Reading available packages... > Choosing modular solver. > Resolving dependencies... > Ready to install glib-0.13.1.0 > Waiting for install task to finish... > Extracting > /opt/cabal/packages/hackage.haskell.org/glib/0.13.1.0/glib-0.13.1.0.tar.gz > to > /tmp/glib-0.13.1.0-3703... > Updating glib.cabal with the latest revision from the index. > creating /tmp/glib-0.13.1.0-3703/glib-0.13.1.0/dist/setup > creating /tmp/glib-0.13.1.0-3703/glib-0.13.1.0/dist > creating /tmp/glib-0.13.1.0-3703/glib-0.13.1.0/dist/setup > Failed to install glib-0.13.1.0 > World file is already up to date. > cabal: Error: some packages failed to install: > glib-0.13.1.0 failed during the configure step. The exception was: > user error (The package 'glib' requires Cabal library version -any && > >=1.18 > but no suitable version is installed.) > cwr at sixpence cabal $ cabal --version > cabal-install version 1.18.0.2 > using version 1.18.1.2 of the Cabal library > cwr at sixpence cabal $ > =================================================================== > > And moving to the default version of cabal, I get: > > =================================================================== > cwr at sixpence cabal $ cabal --verbose --global > --package-db=/opt/cabal/package.conf.d install glib > '/opt/cabal/bin/alex' '--version' > '/opt/cabal/bin/cpphs' '--version' > '/usr/bin/gcc' '-dumpversion' > '/opt/cabal/bin/haddock' '--version' > '/opt/cabal/bin/happy' '--version' > '/usr/bin/hpc' 'version' > looking for tool hsc2hs near compiler in /usr/bin > found hsc2hs in /usr/bin/hsc2hs > '/usr/bin/hsc2hs' '--version' > '/opt/cabal/bin/HsColour' '-version' > '/usr/bin/ghc' '-c' '/tmp/4186.c' '-o' '/tmp/4186.o' > '/usr/bin/ld' '-x' '-r' '/tmp/4186.o' '-o' '/tmp/4187.o' > '/usr/bin/pkg-config' '--version' > '/bin/tar' '--help' > Reading available packages... > Warning: The package list for 'hackage.haskell.org' is 51.4 days old. > Run 'cabal update' to get the latest list of available packages. > Choosing modular solver. > Resolving dependencies... > Ready to install glib-0.13.1.0 > Waiting for install task to finish... > Extracting > /opt/cabal/packages/hackage.haskell.org/glib/0.13.1.0/glib-0.13.1.0.tar.gz > to > /tmp/glib-0.13.1.0-4186... > Updating glib.cabal with the latest revision from the index. > creating /tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist/setup > creating /tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist > creating /tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist/setup > copy /tmp/glib-0.13.1.0-4186/glib-0.13.1.0/Setup.hs to > /tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist/setup/setup.hs > '/usr/bin/ghc' '--make' '-odir' > '/tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist/setup' '-hidir' > '/tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist/setup' '-i' > '-i/tmp/glib-0.13.1.0-4186/glib-0.13.1.0' '-package-db' > '/opt/cabal/package.conf.d' '-package-id' > 'Cabal-1.22.1.1-98c5a01d59dd973fd7113dbb82e82560' > '/tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist/setup/setup.hs' '-o' > '/tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist/setup/setup' '-threaded' > [1 of 2] Compiling SetupWrapper ( > /tmp/glib-0.13.1.0-4186/glib-0.13.1.0/SetupWrapper.hs, > /tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist/setup/SetupWrapper.o ) > [2 of 2] Compiling Main ( > /tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist/setup/setup.hs, > /tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist/setup/Main.o ) > Linking /tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist/setup/setup ... > /tmp/glib-0.13.1.0-4186/glib-0.13.1.0/dist/setup/setup configure > --verbose=2 > --ghc --prefix=/opt/cabal --bindir=/opt/cabal/bin --libdir=/opt/cabal/lib > --libsubdir=glib-0.13.1.0/ghc-7.6.3 --libexecdir=/opt/cabal/libexec > --datadir=/opt/cabal/share --datasubdir=glib-0.13.1.0 > --docdir=/opt/cabal/share/doc/glib-0.13.1.0 > --htmldir=/opt/cabal/share/doc/glib-0.13.1.0/html > --haddockdir=/opt/cabal/share/doc/glib-0.13.1.0/html > --sysconfdir=/opt/cabal/etc --enable-library-profiling > --enable-optimization=2 > --global --package-db=/opt/cabal/package.conf.d --flags=closure_signals > --dependency=utf8-string=utf8-string-0.3.8-51169ff3d90963aa54c0a13eee5c3a53 > --dependency=text=text-1.1.1.3-3a54592a9f7d64cef4851163d5553453 > --dependency=containers=containers-0.5.0.0-e7e1a93d7945e93a00ce12660e9ff290 > > --dependency=bytestring=bytestring-0.10.0.2-14ba8002009bf89cdad6038c30eda3fd > --dependency=base=base-4.6.0.1-220b875e77822b0e1bf50c8f35d37dff > --disable-tests --exact-configuration --disable-benchmarks > [1 of 2] Compiling Gtk2HsSetup ( Gtk2HsSetup.hs, > dist/setup-wrapper/Gtk2HsSetup.o ) > > Gtk2HsSetup.hs:167:16: > Not in scope: `LBI.getComponentLocalBuildInfo' > Failed to install glib-0.13.1.0 > Updating world file... > cabal: Error: some packages failed to install: > glib-0.13.1.0 failed during the configure step. The exception was: > ExitFailure 1 > cwr at sixpence cabal $ > =================================================================== > > Does anyone have any idea how to fix any or all of these errors? > > Thanks - Will > > > _______________________________________________ > 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 pengyu.ut at gmail.com Sat May 16 02:08:27 2015 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 15 May 2015 21:08:27 -0500 Subject: [Haskell-beginners] ld: warning: directory not found for option '-L/private/tmp/ghc20150401-90656-rxy9sj/ghc-7.10.1/gmp-static' Message-ID: Hi, I see the following error. Does anybody know what is wrong? Thanks. $ cat hello.hs main = putStrLn "Hello, World!" $ ghc -o hello hello.hs [1 of 1] Compiling Main ( hello.hs, hello.o ) Linking hello ... ld: warning: directory not found for option '-L/private/tmp/ghc20150401-90656-rxy9sj/ghc-7.10.1/gmp-static' -- Regards, Peng From pengyu.ut at gmail.com Sat May 16 02:45:43 2015 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 15 May 2015 21:45:43 -0500 Subject: [Haskell-beginners] How to check the help page of a function? Message-ID: Hi, I can not find how to check the help page of a function. For example, I want to check the help page of "head". How should I do it? (":help" doesn't seem to help.) -- Regards, Peng From fa-ml at ariis.it Sat May 16 03:21:48 2015 From: fa-ml at ariis.it (Francesco Ariis) Date: Sat, 16 May 2015 05:21:48 +0200 Subject: [Haskell-beginners] How to check the help page of a function? In-Reply-To: References: Message-ID: <20150516032148.GA14162@casa.casa> On Fri, May 15, 2015 at 09:45:43PM -0500, Peng Yu wrote: > Hi, I can not find how to check the help page of a function. > > For example, I want to check the help page of "head". How should I do > it? (":help" doesn't seem to help.) `:t head` will show the function signature (which in 90% of the cases is more than enough to understand what the function does). `:i function` will show the function signature and additionally tell you in which module it is defined. From akaberto at gmail.com Sat May 16 04:21:57 2015 From: akaberto at gmail.com (akash g) Date: Sat, 16 May 2015 09:51:57 +0530 Subject: [Haskell-beginners] ld: warning: directory not found for option '-L/private/tmp/ghc20150401-90656-rxy9sj/ghc-7.10.1/gmp-static' In-Reply-To: References: Message-ID: Seems like other people are also have the same issue. https://github.com/Homebrew/homebrew/issues/38315 On Sat, May 16, 2015 at 7:38 AM, Peng Yu wrote: > Hi, I see the following error. Does anybody know what is wrong? Thanks. > > $ cat hello.hs > main = putStrLn "Hello, World!" > $ ghc -o hello hello.hs > [1 of 1] Compiling Main ( hello.hs, hello.o ) > Linking hello ... > ld: warning: directory not found for option > '-L/private/tmp/ghc20150401-90656-rxy9sj/ghc-7.10.1/gmp-static' > > -- > Regards, > Peng > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mike_k_houghton at yahoo.co.uk Sat May 16 20:58:22 2015 From: mike_k_houghton at yahoo.co.uk (Mike Houghton) Date: Sat, 16 May 2015 21:58:22 +0100 Subject: [Haskell-beginners] Parser Message-ID: <6ACF8725-016D-4B0A-B59F-A889DAFF7AC1@yahoo.co.uk> Hi, I?me writing a simple parser and can test it in GHCI parseTest moveParser "(1,2)->(3,3)? and I get what I expect i.e. Move {from = Location 1 2, to = Location 3 3} I now have a text file (test.txt) with lots of (1,2)->(3,3) (3,6)->(3,9) etc etc and I really can?t see how I get the contents of the text file into the parser!! I have main = do handle <- openFile "test.txt" ReadMode contents <- hGetContents handle !! what goes here!!! - how do I invoke moveParser with contents ?? Thanks Mike -------------- next part -------------- An HTML attachment was scrubbed... URL: From dennis at deathbytape.com Sat May 16 21:18:04 2015 From: dennis at deathbytape.com (Dennis J. McWherter, Jr.) Date: Sat, 16 May 2015 16:18:04 -0500 Subject: [Haskell-beginners] Parser In-Reply-To: <6ACF8725-016D-4B0A-B59F-A889DAFF7AC1@yahoo.co.uk> References: <6ACF8725-016D-4B0A-B59F-A889DAFF7AC1@yahoo.co.uk> Message-ID: It's hard to say exactly, but assuming you have your file new line delimited and you have a function signature like moveParser :: String -> YOUR_TYPE you can try something like this: main = do handle <- openFile "test.txt" contents <- hGetContents handle processedLines <- return (fmap moveParser $ lines contents) hClose handle Does this help? Dennis On Sat, May 16, 2015 at 3:58 PM, Mike Houghton wrote: > Hi, > > I?me writing a simple parser and can test it in GHCI > > parseTest moveParser "(1,2)->(3,3)? > > and I get what I expect i.e. > Move {from = Location 1 2, to = Location 3 3} > > I now have a text file (test.txt) with lots of (1,2)->(3,3) (3,6)->(3,9) > etc etc and > I really can?t see how I get the contents of the text file into the > parser!! > > I have > main = do > handle <- openFile "test.txt" ReadMode > contents <- hGetContents handle > !! what goes here!!! - how do I invoke moveParser with contents ?? > > Thanks > > Mike > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hjgtuyl at chello.nl Sat May 16 23:13:36 2015 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Sun, 17 May 2015 01:13:36 +0200 Subject: [Haskell-beginners] Parser In-Reply-To: References: <6ACF8725-016D-4B0A-B59F-A889DAFF7AC1@yahoo.co.uk> Message-ID: On Sat, 16 May 2015 23:18:04 +0200, Dennis J. McWherter, Jr. wrote: : > processedLines <- return (fmap moveParser $ lines contents) : Or, a bit simpler: let processedLines = fmap moveParser $ lines contents Regards, Henk-Jan van Tuyl -- Folding at home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming -- From hjgtuyl at chello.nl Sat May 16 23:16:44 2015 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Sun, 17 May 2015 01:16:44 +0200 Subject: [Haskell-beginners] How to check the help page of a function? In-Reply-To: References: Message-ID: On Sat, 16 May 2015 04:45:43 +0200, Peng Yu wrote: > Hi, I can not find how to check the help page of a function. > > For example, I want to check the help page of "head". How should I do > it? (":help" doesn't seem to help.) I generally use Hoogle: https://www.fpcomplete.com/hoogle?q=head and sometimes Hayoo: http://hayoo.fh-wedel.de/?query=head Regards, Henk-Jan van Tuyl -- Folding at home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming -- From pengyu.ut at gmail.com Sat May 16 23:18:50 2015 From: pengyu.ut at gmail.com (Peng Yu) Date: Sat, 16 May 2015 18:18:50 -0500 Subject: [Haskell-beginners] How to check the help page of a function? In-Reply-To: References: Message-ID: Many other languages have help pages in the command (see help() in python and R). Why haskell doesn't have such a feature? On Sat, May 16, 2015 at 6:16 PM, Henk-Jan van Tuyl wrote: > On Sat, 16 May 2015 04:45:43 +0200, Peng Yu wrote: > >> Hi, I can not find how to check the help page of a function. >> >> For example, I want to check the help page of "head". How should I do >> it? (":help" doesn't seem to help.) > > > I generally use Hoogle: > https://www.fpcomplete.com/hoogle?q=head > and sometimes Hayoo: > http://hayoo.fh-wedel.de/?query=head > > Regards, > Henk-Jan van Tuyl > > > -- > Folding at home > What if you could share your unused computer power to help find a cure? In > just 5 minutes you can join the world's biggest networked computer and get > us closer sooner. Watch the video. > http://folding.stanford.edu/ > > > http://Van.Tuyl.eu/ > http://members.chello.nl/hjgtuyl/tourdemonad.html > Haskell programming > -- -- Regards, Peng From allbery.b at gmail.com Sat May 16 23:30:30 2015 From: allbery.b at gmail.com (Brandon Allbery) Date: Sat, 16 May 2015 19:30:30 -0400 Subject: [Haskell-beginners] How to check the help page of a function? In-Reply-To: References: Message-ID: On Sat, May 16, 2015 at 7:18 PM, Peng Yu wrote: > Many other languages have help pages in the command (see help() in > python and R). Why haskell doesn't have such a feature? > Because Haskell doesn't predate the web? :p You can build local documentation and access it from ghci with some hooks (see https://wiki.haskell.org/Ghci#Package_and_documentation_lookup although it's a bit outdated), but Haskell is not a dynamic language and ghci is not trying to be its primary developer interface. And you can't exactly hyperlink on a terminal. -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwm at mired.org Sun May 17 00:16:48 2015 From: mwm at mired.org (Mike Meyer) Date: Sat, 16 May 2015 19:16:48 -0500 Subject: [Haskell-beginners] How to check the help page of a function? In-Reply-To: References: Message-ID: On Sat, May 16, 2015 at 6:30 PM, Brandon Allbery wrote: > On Sat, May 16, 2015 at 7:18 PM, Peng Yu wrote: > >> Many other languages have help pages in the command (see help() in >> python and R). Why haskell doesn't have such a feature? >> > > Because Haskell doesn't predate the web? :p > So do Python. And S, for that matter. I don't know about R, but it's a fundamentally harder problem in a Haskell environment than in a Python one. Python forces you to keep the sources around, which has the doc strings in them, and has places to put doc strings in the data describing it's internal objects. So the "help" function is just a tool for examining those. Python's package installation is also more amenable to such, which gives us pydoc instead of hoogle. > You can build local documentation and access it from ghci with some hooks > (see https://wiki.haskell.org/Ghci#Package_and_documentation_lookup > although it's a bit outdated), > Maybe https://wiki.haskell.org/Hoogle#GHCi_Integration would be less outdated? > but Haskell is not a dynamic language and ghci is not trying to be its > primary developer interface. And you can't exactly hyperlink on a terminal. > In that case, you need a more powerful web browser. Or to (as the hoogle command does) install local copies of the documentation. -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael at orlitzky.com Sun May 17 02:09:10 2015 From: michael at orlitzky.com (Michael Orlitzky) Date: Sat, 16 May 2015 22:09:10 -0400 Subject: [Haskell-beginners] How to check the help page of a function? In-Reply-To: References: Message-ID: <5557F846.7090205@orlitzky.com> On 05/16/2015 07:18 PM, Peng Yu wrote: > Many other languages have help pages in the command (see help() in > python and R). Why haskell doesn't have such a feature? > The 40% joking answer is because Haskell functions don't have documentation =) From hjgtuyl at chello.nl Sun May 17 08:24:42 2015 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Sun, 17 May 2015 10:24:42 +0200 Subject: [Haskell-beginners] How to check the help page of a function? In-Reply-To: References: Message-ID: On Sun, 17 May 2015 01:18:50 +0200, Peng Yu wrote: > Many other languages have help pages in the command (see help() in > python and R). Why haskell doesn't have such a feature? GHCi has such a command: :doc For example: Prelude> :doc head Prelude head :: [a] -> a Extract the first element of a list, which must be non-empty. From package base head :: [a] -> a Regards, Henk-Jan van Tuyl -- Folding at home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming -- From pengyu.ut at gmail.com Sun May 17 12:54:36 2015 From: pengyu.ut at gmail.com (Peng Yu) Date: Sun, 17 May 2015 07:54:36 -0500 Subject: [Haskell-beginners] How to check the help page of a function? In-Reply-To: References: Message-ID: > GHCi has such a command: > :doc > > For example: > Prelude> :doc head > Prelude head :: [a] -> a > > Extract the first element of a list, which must be non-empty. > > From package base > head :: [a] -> a Where is it? I don't see it. GHCi, version 7.10.1: http://www.haskell.org/ghc/ :? for help Prelude> :doc head unknown command ':doc' use :? for help. Prelude> -- Regards, Peng From mwm at mired.org Sun May 17 13:00:51 2015 From: mwm at mired.org (Mike Meyer) Date: Sun, 17 May 2015 08:00:51 -0500 Subject: [Haskell-beginners] How to check the help page of a function? In-Reply-To: References: Message-ID: On Sun, May 17, 2015 at 7:54 AM, Peng Yu wrote: > > GHCi has such a command: > > :doc > > > > For example: > > Prelude> :doc head > > Prelude head :: [a] -> a > > > > Extract the first element of a list, which must be non-empty. > > > > From package base > > head :: [a] -> a > > Where is it? I don't see it. > > GHCi, version 7.10.1: http://www.haskell.org/ghc/ :? for help > Prelude> :doc head > unknown command ':doc' > use :? for help. > Prelude> > I suspect the author's environment defines the doc command, as it's not built in. Links to two different ways (one that opened pages in a web browser, and the other that invoked the hoogle command) to do that have already been posted to the thread. -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Sun May 17 13:18:58 2015 From: fa-ml at ariis.it (Francesco Ariis) Date: Sun, 17 May 2015 15:18:58 +0200 Subject: [Haskell-beginners] How to check the help page of a function? In-Reply-To: References: Message-ID: <20150517131858.GA7687@casa.casa> On Sun, May 17, 2015 at 08:00:51AM -0500, Mike Meyer wrote: > I suspect the author's environment defines the doc command, as it's not > built in. Links to two different ways (one that opened pages in a web > browser, and the other that invoked the hoogle command) to do that have > already been posted to the thread. Probably haskell-docs [1] [1] http://hackage.haskell.org/package/haskell-docs From hjgtuyl at chello.nl Sun May 17 14:12:38 2015 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Sun, 17 May 2015 16:12:38 +0200 Subject: [Haskell-beginners] How to check the help page of a function? In-Reply-To: References: Message-ID: On Sun, 17 May 2015 10:24:42 +0200, Henk-Jan van Tuyl wrote: > On Sun, 17 May 2015 01:18:50 +0200, Peng Yu wrote: > >> Many other languages have help pages in the command (see help() in >> python and R). Why haskell doesn't have such a feature? > > GHCi has such a command: > :doc I forgot that this is not the default behavior of GHCi; to get this command, install Hoogle[0][1] and create a file called .ghci in your home directory, with the line: :def doc \x -> return $ ":!hoogle --info \"" ++ x ++ "\"" Regards, Henk-Jan van Tuyl [0] https://hackage.haskell.org/package/hoogle [1] https://wiki.haskell.org/Hoogle -- Folding at home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming -- From mike_k_houghton at yahoo.co.uk Sun May 17 14:28:59 2015 From: mike_k_houghton at yahoo.co.uk (Mike Houghton) Date: Sun, 17 May 2015 15:28:59 +0100 Subject: [Haskell-beginners] Parser In-Reply-To: References: <6ACF8725-016D-4B0A-B59F-A889DAFF7AC1@yahoo.co.uk> Message-ID: <637079A6-B3D9-4C77-B6CA-78267B9A25EF@yahoo.co.uk> Thanks guys. Finally got there and I?m sorry, I should have put more detail in the original question. movesParser :: Parser Moves movesParser = do move <- moveParser char ';' moves <- many moveParser return $ Moves ([move] ++ moves) main = do let mvsIo = readFile ?moves.txt? ? IO String mvs <- mvsIo ? String let m = parse movesParser "Parsing Moves" mvs return m I must say that the people on this list are very helpful and polite. Also Haskell is a challenge but so rewarding. It?s become the ?itch I have to scratch?. Thanks > On 17 May 2015, at 00:13, Henk-Jan van Tuyl wrote: > > On Sat, 16 May 2015 23:18:04 +0200, Dennis J. McWherter, Jr. wrote: > > : >> processedLines <- return (fmap moveParser $ lines contents) > : > > Or, a bit simpler: > let processedLines = fmap moveParser $ lines contents > > Regards, > Henk-Jan van Tuyl > > > -- > Folding at home > What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. > http://folding.stanford.edu/ > > > http://Van.Tuyl.eu/ > http://members.chello.nl/hjgtuyl/tourdemonad.html > Haskell programming > -- From ky3 at atamo.com Sun May 17 17:27:37 2015 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Mon, 18 May 2015 00:27:37 +0700 Subject: [Haskell-beginners] How to check the help page of a function? In-Reply-To: References: Message-ID: On Sun, May 17, 2015 at 6:18 AM, Peng Yu wrote: > Many other languages have help pages in the command (see help() in > python and R). Why haskell doesn't have such a feature? > You could flip the question around and ask, why do Python and R insist on incorporating emacs functionality in their REPLs instead of keeping things orthogonal. Otherwise, there's a lot of repetition. As Brandon explained, ghci isn't meant to be the everything-and-the-kitchen-sink development environment. It used to be that someone starting Haskell would have learned Unix and its ethos beforehand. That's not a ding against you, btw, just an observation that ghci was designed in an earlier era. Patches to ghci are most welcome! -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Sun May 17 19:23:46 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Sun, 17 May 2015 21:23:46 +0200 Subject: [Haskell-beginners] which ones to use Message-ID: <5558EAC2.2040808@home.nl> Hello, My linux distro has haskell-platform not avaible. But things like ghc and cabal are avaible. Which ones does I need so I can programm in Haskell with SublimeText 3 as editor ? Roelof --- Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. http://www.avast.com From sumit.sahrawat.apm13 at iitbhu.ac.in Sun May 17 19:25:44 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Mon, 18 May 2015 00:55:44 +0530 Subject: [Haskell-beginners] which ones to use In-Reply-To: <5558EAC2.2040808@home.nl> References: <5558EAC2.2040808@home.nl> Message-ID: You would require atleast ghc & cabal. Everything else can be installed using cabal. Try getting ghc version >= 7.8.3 and cabal version >= 1.20 On 18 May 2015 at 00:53, Roelof Wobben wrote: > Hello, > > My linux distro has haskell-platform not avaible. > But things like ghc and cabal are avaible. > > Which ones does I need so I can programm in Haskell with SublimeText 3 as > editor ? > > Roelof > > > --- > Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. > http://www.avast.com > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From pengyu.ut at gmail.com Sun May 17 21:37:18 2015 From: pengyu.ut at gmail.com (Peng Yu) Date: Sun, 17 May 2015 16:37:18 -0500 Subject: [Haskell-beginners] ld: warning: directory not found for option '-L/private/tmp/ghc20150401-90656-rxy9sj/ghc-7.10.1/gmp-static' In-Reply-To: References: Message-ID: What is the solution? On Fri, May 15, 2015 at 11:21 PM, akash g wrote: > Seems like other people are also have the same issue. > > https://github.com/Homebrew/homebrew/issues/38315 > > On Sat, May 16, 2015 at 7:38 AM, Peng Yu wrote: >> >> Hi, I see the following error. Does anybody know what is wrong? Thanks. >> >> $ cat hello.hs >> main = putStrLn "Hello, World!" >> $ ghc -o hello hello.hs >> [1 of 1] Compiling Main ( hello.hs, hello.o ) >> Linking hello ... >> ld: warning: directory not found for option >> '-L/private/tmp/ghc20150401-90656-rxy9sj/ghc-7.10.1/gmp-static' >> >> -- >> Regards, >> Peng >> _______________________________________________ >> 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 > -- Regards, Peng From dasuraga at gmail.com Mon May 18 02:17:22 2015 From: dasuraga at gmail.com (Raphael Gaschignard) Date: Mon, 18 May 2015 02:17:22 +0000 Subject: [Haskell-beginners] How to check the help page of a function? In-Reply-To: References: Message-ID: Kind of surprised at the attitude shown in this thread. It's entirely reasonable to expect a REPL to offer help functionality (especially coming from Python/R), even if , digging deeper, it turns out to be difficult to offer. Mainly because docs aren't auto-included with packages. ghci isn't meant to be a full-blown dev environment, but hey the python console isn't meant to either. I think a tangential issue is that there's no "blessed" solution, so we're worried about lock-in. https://wiki.haskell.org/GHC/GHCi <-- this page describes how to set up your environment to get output from hoogle into ghci (by doing :hoogle map for example). On Mon, May 18, 2015 at 2:28 AM Kim-Ee Yeoh wrote: > > On Sun, May 17, 2015 at 6:18 AM, Peng Yu wrote: > >> Many other languages have help pages in the command (see help() in >> python and R). Why haskell doesn't have such a feature? >> > > You could flip the question around and ask, why do Python and R insist on > incorporating emacs functionality in their REPLs instead of keeping things > orthogonal. Otherwise, there's a lot of repetition. > > As Brandon explained, ghci isn't meant to be the > everything-and-the-kitchen-sink development environment. > > It used to be that someone starting Haskell would have learned Unix and > its ethos beforehand. That's not a ding against you, btw, just an > observation that ghci was designed in an earlier era. Patches to ghci are > most welcome! > > -- Kim-Ee > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Mon May 18 02:33:44 2015 From: allbery.b at gmail.com (Brandon Allbery) Date: Sun, 17 May 2015 22:33:44 -0400 Subject: [Haskell-beginners] How to check the help page of a function? In-Reply-To: References: Message-ID: On Sun, May 17, 2015 at 10:17 PM, Raphael Gaschignard wrote: > ghci isn't meant to be a full-blown dev environment, but hey the python > console isn't meant to either. I should stress that I did not intend so much to say that the OP was asking for something out of line; more that ghci is known to be old, limited, and annoying to maintain and really needs to be replaced --- someday. Unfortunately, that replacement will require a lot of work, because ghc-api. :/ -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From magnus at therning.org Mon May 18 10:01:47 2015 From: magnus at therning.org (Magnus Therning) Date: Mon, 18 May 2015 12:01:47 +0200 Subject: [Haskell-beginners] which ones to use In-Reply-To: <5558EAC2.2040808@home.nl> References: <5558EAC2.2040808@home.nl> Message-ID: On 17 May 2015 at 21:23, Roelof Wobben wrote: > Hello, > > My linux distro has haskell-platform not avaible. > But things like ghc and cabal are avaible. Which distro is it? /M -- Magnus Therning OpenPGP: 0xAB4DFBA4 email: magnus at therning.org jabber: magnus at therning.org twitter: magthe http://therning.org/magnus From dan9131 at gmail.com Mon May 18 11:23:41 2015 From: dan9131 at gmail.com (Dananji Liyanage) Date: Mon, 18 May 2015 16:53:41 +0530 Subject: [Haskell-beginners] Iterating through lists Message-ID: Hi All, I'm building a 9x9 grid like list, and I want to extract each column of that grid. My input is a list of integers as follows; input = [0, 0, 0, 0, 0, 0, 4, 0, 9, 0, 0, 0, 0, 8, 0, 0, 5, 0, 7, 0, 2, 4, 5, 3, 6, 0, 0, 6, 7, 0, 0, 0, 1, 5, 0, 2, 2, 0, 8, 7, 0, 4, 3, 0, 1, 9, 0, 4, 5, 0, 0, 0, 8, 6, 0, 0, 6, 3, 1, 9, 8, 0, 7, 0, 2, 0, 0, 7, 0, 0, 0, 0, 1, 0, 7, 0, 0, 0, 0, 0, 0] I tried list comprehension with 'take' function in lists as follows; columns xs = [x | x <- (take 1 xs)] : columns (drop 9 xs) --> columns input This extracts only the first column. How I can go for the other columns? -- Regards, Dananji Liyanage -------------- next part -------------- An HTML attachment was scrubbed... URL: From magnus at therning.org Mon May 18 11:36:11 2015 From: magnus at therning.org (Magnus Therning) Date: Mon, 18 May 2015 13:36:11 +0200 Subject: [Haskell-beginners] Iterating through lists In-Reply-To: References: Message-ID: On 18 May 2015 at 13:23, Dananji Liyanage wrote: > Hi All, > > I'm building a 9x9 grid like list, and I want to extract each column of that > grid. > > My input is a list of integers as follows; > > input = [0, 0, 0, 0, 0, 0, 4, 0, 9, > 0, 0, 0, 0, 8, 0, 0, 5, 0, > 7, 0, 2, 4, 5, 3, 6, 0, 0, > 6, 7, 0, 0, 0, 1, 5, 0, 2, > 2, 0, 8, 7, 0, 4, 3, 0, 1, > 9, 0, 4, 5, 0, 0, 0, 8, 6, > 0, 0, 6, 3, 1, 9, 8, 0, 7, > 0, 2, 0, 0, 7, 0, 0, 0, 0, > 1, 0, 7, 0, 0, 0, 0, 0, 0] > > I tried list comprehension with 'take' function in lists as follows; > > columns xs = [x | x <- (take 1 xs)] : columns (drop 9 xs) --> columns input > > This extracts only the first column. How I can go for the other columns? One easy way would be to first look at the `split` package to find the function `chunksOf` and then simply `Data.List.transpose` the result. /M -- Magnus Therning OpenPGP: 0xAB4DFBA4 email: magnus at therning.org jabber: magnus at therning.org twitter: magthe http://therning.org/magnus From hjgtuyl at chello.nl Mon May 18 11:39:07 2015 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Mon, 18 May 2015 13:39:07 +0200 Subject: [Haskell-beginners] Iterating through lists In-Reply-To: References: Message-ID: On Mon, 18 May 2015 13:23:41 +0200, Dananji Liyanage wrote: > Hi All, > > I'm building a 9x9 grid like list, and I want to extract each column of > that grid. > > My input is a list of integers as follows; > > input = [0, 0, 0, 0, 0, 0, 4, 0, 9, > 0, 0, 0, 0, 8, 0, 0, 5, 0, > 7, 0, 2, 4, 5, 3, 6, 0, 0, > 6, 7, 0, 0, 0, 1, 5, 0, 2, > 2, 0, 8, 7, 0, 4, 3, 0, 1, > 9, 0, 4, 5, 0, 0, 0, 8, 6, > 0, 0, 6, 3, 1, 9, 8, 0, 7, > 0, 2, 0, 0, 7, 0, 0, 0, 0, > 1, 0, 7, 0, 0, 0, 0, 0, 0] Try the function chunksOf of package split[0] Regards, Henk-Jan van Tuyl [0] http://haddocks.fpcomplete.com/fp/7.8/20140916-162/split/Data-List-Split-Internals.html#v:chunksOf -- Folding at home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming -- From konstantin.saveljev at gmail.com Mon May 18 12:03:55 2015 From: konstantin.saveljev at gmail.com (Konstantin Saveljev) Date: Mon, 18 May 2015 15:03:55 +0300 Subject: [Haskell-beginners] profiling :: memory allocation Message-ID: Hello, I'm trying to figure out how to reduce the allocation rate in my program. But I'm stuck with the profile report which has the top allocator to be shown like this: COST CENTRE MODULE %time %alloc >>= Internal 20.5 22.6 I do not understand what it actually means? Can anyone explain to me or is there anything I can do so it shows some more information (instead of showing the bind operator >>=) ? Thanks, Konstantin -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Mon May 18 10:43:35 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Mon, 18 May 2015 12:43:35 +0200 Subject: [Haskell-beginners] which ones to use In-Reply-To: References: <5558EAC2.2040808@home.nl> Message-ID: <5559C257.7030805@home.nl> Chakra linux. Magnus Therning schreef op 18-5-2015 om 12:01: > On 17 May 2015 at 21:23, Roelof Wobben wrote: >> Hello, >> >> My linux distro has haskell-platform not avaible. >> But things like ghc and cabal are avaible. > Which distro is it? > > /M > --- Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. http://www.avast.com From magnus at therning.org Mon May 18 13:21:02 2015 From: magnus at therning.org (Magnus Therning) Date: Mon, 18 May 2015 15:21:02 +0200 Subject: [Haskell-beginners] which ones to use In-Reply-To: <5559C257.7030805@home.nl> References: <5558EAC2.2040808@home.nl> <5559C257.7030805@home.nl> Message-ID: On 18 May 2015 at 12:43, Roelof Wobben wrote: > Chakra linux. Since it's based on Arch can you use its repos? There's an ArchHaskell repo with a few packages. /M -- Magnus Therning OpenPGP: 0xAB4DFBA4 email: magnus at therning.org jabber: magnus at therning.org twitter: magthe http://therning.org/magnus From sumit.sahrawat.apm13 at iitbhu.ac.in Mon May 18 13:38:26 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Mon, 18 May 2015 19:08:26 +0530 Subject: [Haskell-beginners] which ones to use In-Reply-To: References: <5558EAC2.2040808@home.nl> <5559C257.7030805@home.nl> Message-ID: Arch directly provides ghc-7.10.1 and cabal-install-1.22.2.0 in its repositories. You can use those. There used to be a haskell-platform package on the AUR, but it's been deprecated in favor of the five packages (ghc, cabal-install, happy, alex, haddock) Take a look here: https://wiki.archlinux.org/index.php/Haskell On 18 May 2015 at 18:51, Magnus Therning wrote: > On 18 May 2015 at 12:43, Roelof Wobben wrote: > > Chakra linux. > > Since it's based on Arch can you use its repos? > > There's an ArchHaskell repo with a few packages. > > /M > > -- > Magnus Therning OpenPGP: 0xAB4DFBA4 > email: magnus at therning.org jabber: magnus at therning.org > twitter: magthe http://therning.org/magnus > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan9131 at gmail.com Tue May 19 03:00:57 2015 From: dan9131 at gmail.com (Dananji Liyanage) Date: Tue, 19 May 2015 08:30:57 +0530 Subject: [Haskell-beginners] Iterating through lists In-Reply-To: References: Message-ID: Thank you all!! Got it working with Data.List.transpose On Mon, May 18, 2015 at 5:09 PM, Henk-Jan van Tuyl wrote: > On Mon, 18 May 2015 13:23:41 +0200, Dananji Liyanage > wrote: > > Hi All, >> >> I'm building a 9x9 grid like list, and I want to extract each column of >> that grid. >> >> My input is a list of integers as follows; >> >> input = [0, 0, 0, 0, 0, 0, 4, 0, 9, >> 0, 0, 0, 0, 8, 0, 0, 5, 0, >> 7, 0, 2, 4, 5, 3, 6, 0, 0, >> 6, 7, 0, 0, 0, 1, 5, 0, 2, >> 2, 0, 8, 7, 0, 4, 3, 0, 1, >> 9, 0, 4, 5, 0, 0, 0, 8, 6, >> 0, 0, 6, 3, 1, 9, 8, 0, 7, >> 0, 2, 0, 0, 7, 0, 0, 0, 0, >> 1, 0, 7, 0, 0, 0, 0, 0, 0] >> > > Try the function chunksOf of package split[0] > > Regards, > Henk-Jan van Tuyl > > > [0] > http://haddocks.fpcomplete.com/fp/7.8/20140916-162/split/Data-List-Split-Internals.html#v:chunksOf > > > -- > Folding at home > What if you could share your unused computer power to help find a cure? In > just 5 minutes you can join the world's biggest networked computer and get > us closer sooner. Watch the video. > http://folding.stanford.edu/ > > > http://Van.Tuyl.eu/ > http://members.chello.nl/hjgtuyl/tourdemonad.html > Haskell programming > -- > -- Regards, Dananji Liyanage -------------- next part -------------- An HTML attachment was scrubbed... URL: From vgoel at fastmail.com Wed May 20 11:47:00 2015 From: vgoel at fastmail.com (Vaibhav Goel) Date: Wed, 20 May 2015 04:47:00 -0700 Subject: [Haskell-beginners] Question regarding CIS 194 Homework Assignment 1 Message-ID: <1432122420.2427830.273659377.5003DAFD@webmail.messagingengine.com> My apologies, this is only tangentially related to Haskell and I am not looking for a solution. I am confused with the assignment itself and hence asking here. The assignment (https://www.seas.upenn.edu/~cis194/spring13/hw/01-intro.pdf) says: ====== BEGIN Double the value of every second digit beginning from the right. That is, the last digit is unchanged; the second-to-last digit is dou- bled; the third-to-last digit is unchanged; and so on. For example, [1,3,8,6] becomes [2,3,16,6] Add the digits of the doubled values and the undoubled dig- its from the original number. For example, [2,3,16,6] becomes 2+3+1+6+6 = 18 ======== END Firstly, I am confused as to how the doubled values are being added to the undoubled number in the above example. It looks like only the individual numbers of the doubled values are being added Secondly, later on in the assignment: ======== BEGIN Example : validate 4012888888881881 = True Example : validate 4012888888881882 = False ========= END If we are to follow the algorithm described (double the value of "every second digit" beginning from the right, last digit unchanged", then the above numbers are identical EXCEPT For the last digits (1 and 2) Any help is appreciated in decoding these instructions. Again please do not provide Haskell code, since I want to attempt to write it myself. I am just looking for help with the algorithm. Regards, From konstantin.saveljev at gmail.com Wed May 20 12:09:01 2015 From: konstantin.saveljev at gmail.com (Konstantin Saveljev) Date: Wed, 20 May 2015 15:09:01 +0300 Subject: [Haskell-beginners] Question regarding CIS 194 Homework Assignment 1 In-Reply-To: <1432122420.2427830.273659377.5003DAFD@webmail.messagingengine.com> References: <1432122420.2427830.273659377.5003DAFD@webmail.messagingengine.com> Message-ID: Hey, >> Firstly, I am confused as to how the doubled values are being added to >> the undoubled number in the above example. It looks like only the >> individual numbers of the doubled values are being added The assignment states "Add the *digits* of the doubled values and the undoubled digits", so it specifically states to add digits (which are 0 1 2 3 ... 9) and that is why when you have [2, 3, 16, 6] you do not simply do 2 + 3 + 16 + 6 but you do it digit wise 2 + 3 + 1 + 6 + 6. That is [2, 3, 16, 6] becomes "23166" and you simply sum all the digits. >> If we are to follow the algorithm described (double the value of "every >> second digit" beginning from the right, last digit unchanged", then the >> above numbers are identical EXCEPT For the last digits (1 and 2) The assignment states "Add the digits of the doubled values *and the undoubled digits*", so the sum will be different for the two numbers provided in the example because both doubled and undoubled values (their digits actually) are being summed. That is why for the first number validates gives True and for the other it gives False. Hope that was clear enough for you to understand. You got confused by a single sentence in the assignment. Konstantin On Wed, May 20, 2015 at 2:47 PM, Vaibhav Goel wrote: > My apologies, this is only tangentially related to Haskell and I am not > looking for a solution. I am confused with the assignment itself and > hence asking here. > > The assignment > (https://www.seas.upenn.edu/~cis194/spring13/hw/01-intro.pdf) says: > > ====== BEGIN > Double the value of every second digit beginning from the right. > That is, the last digit is unchanged; the second-to-last digit is dou- > bled; the third-to-last digit is unchanged; and so on. For example, > [1,3,8,6] > becomes > [2,3,16,6] > > Add the digits of the doubled values and the undoubled dig- > its from the original number. For example, > [2,3,16,6] > becomes > 2+3+1+6+6 = 18 > ======== END > > Firstly, I am confused as to how the doubled values are being added to > the undoubled number in the above example. It looks like only the > individual numbers of the doubled values are being added > > Secondly, later on in the assignment: > > ======== BEGIN > Example > : > validate 4012888888881881 = True > Example > : > validate 4012888888881882 = False > > ========= END > > If we are to follow the algorithm described (double the value of "every > second digit" beginning from the right, last digit unchanged", then the > above numbers are identical EXCEPT For the last digits (1 and 2) > > > Any help is appreciated in decoding these instructions. Again please do > not provide Haskell code, since I want to attempt to write it myself. I > am just looking for help with the algorithm. > > Regards, > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Sat May 23 06:58:50 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Sat, 23 May 2015 08:58:50 +0200 Subject: [Haskell-beginners] Couldn't match expected type `(a0 -> [a0]) -> [a0]', with actual type `[a0]' Message-ID: <5560252A.60306@home.nl> Hello, For some reasons my file's are corrupted. I had repair them with success except this one. Here is the code : toDigits number | number <= 0 = [] | otherwise = toDigits' [] number where toDigits' acc 0 = acc toDigits' acc number = ((number `mod` 10 ): acc) (toDigits' (number `mod` 10)) main = print $ toDigits 123 and here is the error: Couldn't match expected type `(a0 -> [a0]) -> [a0]' with actual type `[a0]' The function `(number `mod` 10) : acc' is applied to one argument, but its type `[a0]' has none In the expression: ((number `mod` 10) : acc) (toDigits' (number `mod` 10)) In an equation for toDigits': toDigits' acc number = ((number `mod` 10) : acc) (toDigits' (number `mod` 10)) Roelof --- Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. http://www.avast.com From sumit.sahrawat.apm13 at iitbhu.ac.in Sat May 23 11:59:05 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Sat, 23 May 2015 17:29:05 +0530 Subject: [Haskell-beginners] Couldn't match expected type `(a0 -> [a0]) -> [a0]', with actual type `[a0]' In-Reply-To: <5560252A.60306@home.nl> References: <5560252A.60306@home.nl> Message-ID: The error lies here: toDigits' acc number = ((number `mod` 10 ): acc) (toDigits' (number `mod` 10)) It should instead be toDigits' acc number = (number `mod` 10) : (toDigits' acc (number `mod` 10)) My suggestion would be to look at it like a fold. toDigits' :: Integral a => a -> a -> [a] toDigits' acc 0 = [acc] toDigits' acc n = n `mod` 10 : toDigits' acc (n `div` 10) Now this gives the digits in the reverse order, so in toDigits, you can reverse it. A good exercise would now be to re-write this as a fold. Graham Hutton has a good paper about it. [1] The best way would be to directly convert the number to a string using show, but that's not the point of the exercise. [1]: https://www.cs.nott.ac.uk/~gmh/fold.pdf On 23 May 2015 at 12:28, Roelof Wobben wrote: > Hello, > > For some reasons my file's are corrupted. > I had repair them with success except this one. > > Here is the code : > > toDigits number > | number <= 0 = [] > | otherwise = toDigits' [] number > where > toDigits' acc 0 = acc > toDigits' acc number = ((number `mod` 10 ): acc) (toDigits' (number > `mod` 10)) > > main = print $ toDigits 123 > > > and here is the error: > > Couldn't match expected type `(a0 -> [a0]) -> [a0]' > with actual type `[a0]' > The function `(number `mod` 10) : acc' is applied to one argument, > but its type `[a0]' has none > In the expression: > ((number `mod` 10) : acc) (toDigits' (number `mod` 10)) > In an equation for toDigits': > toDigits' acc number > = ((number `mod` 10) : acc) (toDigits' (number `mod` 10)) > > > Roelof > > > --- > Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. > http://www.avast.com > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwm at mired.org Sat May 23 12:45:56 2015 From: mwm at mired.org (Mike Meyer) Date: Sat, 23 May 2015 07:45:56 -0500 Subject: [Haskell-beginners] Couldn't match expected type `(a0 -> [a0]) -> [a0]', with actual type `[a0]' In-Reply-To: References: <5560252A.60306@home.nl> Message-ID: Try this: toDigits' :: Integral a => [a] -> a -> [a] toDigits' acc 0 = acc toDigits' acc n = toDigits' (n `mod` 10 : acc) (n `div` 10) If the accumulator in a recursive function doesn't accumulate anything during some recursive call, but is just passed on unchanged, then you might as well make it a free variable. Or eliminate it entirely if it's unused. You can now use a functional programming idiom, and assign the function toDigits to the function toDigits' [], like so: toDigits :: Integral a => a -> [a] toDigits = toDigits' [] On Sat, May 23, 2015 at 6:59 AM, Sumit Sahrawat, Maths & Computing, IIT (BHU) wrote: > The error lies here: > > toDigits' acc number = ((number `mod` 10 ): acc) (toDigits' (number `mod` > 10)) > > It should instead be > > toDigits' acc number = (number `mod` 10) : (toDigits' acc (number `mod` > 10)) > > My suggestion would be to look at it like a fold. > > toDigits' :: Integral a => a -> a -> [a] > toDigits' acc 0 = [acc] > toDigits' acc n = n `mod` 10 : toDigits' acc (n `div` 10) > > Now this gives the digits in the reverse order, so in toDigits, you can > reverse it. > > A good exercise would now be to re-write this as a fold. Graham Hutton has > a good paper about it. [1] > > The best way would be to directly convert the number to a string using > show, but that's not the point of the exercise. > > [1]: https://www.cs.nott.ac.uk/~gmh/fold.pdf > > On 23 May 2015 at 12:28, Roelof Wobben wrote: > >> Hello, >> >> For some reasons my file's are corrupted. >> I had repair them with success except this one. >> >> Here is the code : >> >> toDigits number >> | number <= 0 = [] >> | otherwise = toDigits' [] number >> where >> toDigits' acc 0 = acc >> toDigits' acc number = ((number `mod` 10 ): acc) (toDigits' (number >> `mod` 10)) >> >> main = print $ toDigits 123 >> >> >> and here is the error: >> >> Couldn't match expected type `(a0 -> [a0]) -> [a0]' >> with actual type `[a0]' >> The function `(number `mod` 10) : acc' is applied to one argument, >> but its type `[a0]' has none >> In the expression: >> ((number `mod` 10) : acc) (toDigits' (number `mod` 10)) >> In an equation for toDigits': >> toDigits' acc number >> = ((number `mod` 10) : acc) (toDigits' (number `mod` 10)) >> >> >> Roelof >> >> >> --- >> Dit e-mailbericht is gecontroleerd op virussen met Avast >> antivirussoftware. >> http://www.avast.com >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > > > -- > Regards > > Sumit Sahrawat > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwm at mired.org Sat May 23 19:38:07 2015 From: mwm at mired.org (Mike Meyer) Date: Sat, 23 May 2015 14:38:07 -0500 Subject: [Haskell-beginners] ClassyPrelude vs. Haskell.Language.Interpreter Message-ID: I'm trying to run interpreted code via ClassyPrelude, and getting some results that make me suspect a bug in the Prelude's type system. Or maybe the interpreter. Anyway, here's a bit of code that works as expected: {-# LANGUAGE NoImplicitPrelude #-} import ClassyPrelude import Language.Haskell.Interpreter main :: IO () main = do fun <- runInterpreter $ makeFun "reverse" case fun of Left e -> print e Right f -> readFile "/etc/motd" >>= hPut stdout . f makeFun expr = do set [languageExtensions := [NoImplicitPrelude]] setImportsQ [("ClassyPrelude", Nothing)] interpret expr (as :: Text -> Text) I don't think I can simplify this any further. It works as expected, and also works as expected, and prints out the contents of /etc/motd reversed. However, if you change the type signature in the last line from Text -> Text to LText -> Ltext (to get lazy text), you get no output. But if you change the function in the first line after main from "reverse" to "id", it works. So far, it might be an issue with lazy IO. However, change the type signature in the last line to LText -> Text. In this case, there is no output for either value of the expression. I expect an error in this case, as neither id nor reverse should be able to have the type LText -> Text! So, is there something I missed in either ClassyPrelude or the Interpreter? Or is this a subtle interaction, in which case can someone suggest a workaround? Or have I found a bug in one of the two? -------------- next part -------------- An HTML attachment was scrubbed... URL: From rene.klacan at gmail.com Sun May 24 15:43:30 2015 From: rene.klacan at gmail.com (=?UTF-8?B?UmVuw6kgS2xhxI1hbg==?=) Date: Sun, 24 May 2015 16:43:30 +0100 Subject: [Haskell-beginners] Crawling page and making json out of it Message-ID: Hi all, I have a small example that opens page and creates a json out of it https://gist.github.com/reneklacan/262eef04a3bc67607dd8 It works correctly and it returns desired results. But I am sure there is a better way (or more Haskell way) how to write it. Especially I don't really like how *getInfo* function looks like. Get you please give me an advice how to make it more ellegant or tell me what I'm doing wrong. Thanks Rene -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan9131 at gmail.com Mon May 25 06:44:32 2015 From: dan9131 at gmail.com (Dananji Liyanage) Date: Mon, 25 May 2015 12:14:32 +0530 Subject: [Haskell-beginners] Using IO values for computations Message-ID: Hi All, I'm writing a code, where the input is read from a text file using: readValues = readFile "Input.txt" Since the type of this is 'IO String', I can't use this in the consequent functions. For an example: I want to split this as follows within another function extractInput url method template | isURI url == True = getList values components | otherwise = [] where components = splitTemplate readValues values = getURL (splitURL url) method This gives the following error: Couldn't match type ?IO String? with ?[Char]? Expected type: String Actual type: IO String How can I solve this? Thanks in advance! -- Regards, Dananji Liyanage -------------- next part -------------- An HTML attachment was scrubbed... URL: From magnus at therning.org Mon May 25 12:29:12 2015 From: magnus at therning.org (Magnus Therning) Date: Mon, 25 May 2015 14:29:12 +0200 Subject: [Haskell-beginners] Using IO values for computations In-Reply-To: References: Message-ID: On 25 May 2015 at 08:44, Dananji Liyanage wrote: > Hi All, > > I'm writing a code, where the input is read from a text file using: > readValues = readFile "Input.txt" > > Since the type of this is 'IO String', I can't use this in the consequent > functions. > > For an example: I want to split this as follows within another function > > extractInput url method template > | isURI url == True = getList values components > | otherwise = [] > where components = splitTemplate readValues > values = getURL (splitURL url) method > > This gives the following error: > > Couldn't match type ?IO String? with ?[Char]? > Expected type: String > Actual type: IO String > > How can I solve this? Start with reading some basic Haskell book/tutorial. That should tell you how to e.g. use 'do' notation, or `liftM`, to achieve what you want. /M -- Magnus Therning OpenPGP: 0xAB4DFBA4 email: magnus at therning.org jabber: magnus at therning.org twitter: magthe http://therning.org/magnus From grzegorzmilka at gmail.com Sat May 23 08:29:30 2015 From: grzegorzmilka at gmail.com (Grzegorz Milka) Date: Sat, 23 May 2015 10:29:30 +0200 Subject: [Haskell-beginners] Couldn't match expected type `(a0 -> [a0]) -> [a0]', with actual type `[a0]' In-Reply-To: <5560252A.60306@home.nl> References: <5560252A.60306@home.nl> Message-ID: <55603A6A.4020507@gmail.com> Hi, The faulty expression is this one: ((number `mod` 10 ): acc) (toDigits' (number `mod` 10)) The first expression: ((number `mod` 10 ): acc) is a list. You concatenate a number to acc. Therefore what you are doing is calling a list with an argument: (toDigits' (number `mod` 10)). That's what the error says. The first expression is called with one argument, but its is a list ([a0]), which is not a function, therefore can not be called. I think you meant something like: toDigits' acc number = toDigits' ((number `mod` 10 ): acc) (number `div` 10) Best, Greg On 23.05.2015 08:58, Roelof Wobben wrote: > Hello, > > For some reasons my file's are corrupted. > I had repair them with success except this one. > > Here is the code : > > toDigits number > | number <= 0 = [] > | otherwise = toDigits' [] number > where > toDigits' acc 0 = acc > toDigits' acc number = ((number `mod` 10 ): acc) (toDigits' > (number `mod` 10)) > > main = print $ toDigits 123 > > > and here is the error: > > Couldn't match expected type `(a0 -> [a0]) -> [a0]' > with actual type `[a0]' > The function `(number `mod` 10) : acc' is applied to one argument, > but its type `[a0]' has none > In the expression: > ((number `mod` 10) : acc) (toDigits' (number `mod` 10)) > In an equation for toDigits': > toDigits' acc number > = ((number `mod` 10) : acc) (toDigits' (number `mod` 10)) > > > Roelof > > > --- > Dit e-mailbericht is gecontroleerd op virussen met Avast > antivirussoftware. > http://www.avast.com > > _______________________________________________ > 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: 836 bytes Desc: OpenPGP digital signature URL: From k-bx at k-bx.com Mon May 25 16:23:04 2015 From: k-bx at k-bx.com (Kostiantyn Rybnikov) Date: Mon, 25 May 2015 19:23:04 +0300 Subject: [Haskell-beginners] Using IO values for computations In-Reply-To: References: Message-ID: Dananji, Haskell explicitly separates "pure" from "impure", so "readFile " returns not a string, but rather an action, which tells haskell to read a string. In order to "use" a result of some IO action as a pure value, you have several ways, most popula of which is a do-notation. main :: IO () main = do s <- readFile "somefile.txt" putStrLn (show (doSplit s)) In the code above, variable "s" is "pure", it has type String and you can use it as you want. Do-notation is essentially a sugar to callback mechanism, where in order to use a value of some IO-computation you write a function-callback that will be called with a pure value of computation result. This code is the same as previous one, but without do-notation: main :: IO () main = readFile "somefile.txt" >>= (\s -> putStrLn (show (doSplit s))) I highly recommend reading "Learn You A Haskell" book http://learnyouahaskell.com/ , which explained these concepts really well to me. On Mon, May 25, 2015 at 9:44 AM, Dananji Liyanage wrote: > Hi All, > > I'm writing a code, where the input is read from a text file using: > readValues = readFile "Input.txt" > > Since the type of this is 'IO String', I can't use this in the consequent > functions. > > For an example: I want to split this as follows within another function > > extractInput url method template > | isURI url == True = getList values components > | otherwise = [] > where components = splitTemplate readValues > values = getURL (splitURL url) method > > This gives the following error: > > Couldn't match type ?IO String? with ?[Char]? > Expected type: String > Actual type: IO String > > How can I solve this? > > Thanks in advance! > > -- > Regards, > Dananji Liyanage > > _______________________________________________ > 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 dan9131 at gmail.com Tue May 26 03:29:01 2015 From: dan9131 at gmail.com (Dananji Liyanage) Date: Tue, 26 May 2015 08:59:01 +0530 Subject: [Haskell-beginners] Using IO values for computations In-Reply-To: References: Message-ID: Thank you for the nice explanation! I understood it for some extent, and will read further on I/O. On Mon, May 25, 2015 at 9:53 PM, Kostiantyn Rybnikov wrote: > Dananji, > > Haskell explicitly separates "pure" from "impure", so "readFile " > returns not a string, but rather an action, which tells haskell to read a > string. In order to "use" a result of some IO action as a pure value, you > have several ways, most popula of which is a do-notation. > > main :: IO () > main = do > s <- readFile "somefile.txt" > putStrLn (show (doSplit s)) > > In the code above, variable "s" is "pure", it has type String and you can > use it as you want. Do-notation is essentially a sugar to callback > mechanism, where in order to use a value of some IO-computation you write a > function-callback that will be called with a pure value of computation > result. This code is the same as previous one, but without do-notation: > > main :: IO () > main = > readFile "somefile.txt" >>= (\s -> > putStrLn (show (doSplit s))) > > I highly recommend reading "Learn You A Haskell" book > http://learnyouahaskell.com/ , which explained these concepts really well > to me. > > On Mon, May 25, 2015 at 9:44 AM, Dananji Liyanage > wrote: > >> Hi All, >> >> I'm writing a code, where the input is read from a text file using: >> readValues = readFile "Input.txt" >> >> Since the type of this is 'IO String', I can't use this in the >> consequent functions. >> >> For an example: I want to split this as follows within another function >> >> extractInput url method template >> | isURI url == True = getList values components >> | otherwise = [] >> where components = splitTemplate readValues >> values = getURL (splitURL url) method >> >> This gives the following error: >> >> Couldn't match type ?IO String? with ?[Char]? >> Expected type: String >> Actual type: IO String >> >> How can I solve this? >> >> Thanks in advance! >> >> -- >> Regards, >> Dananji Liyanage >> >> _______________________________________________ >> 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 > > -- Regards, Dananji Liyanage -------------- next part -------------- An HTML attachment was scrubbed... URL: From shishir.srivastava at gmail.com Thu May 28 13:57:22 2015 From: shishir.srivastava at gmail.com (Shishir Srivastava) Date: Thu, 28 May 2015 14:57:22 +0100 Subject: [Haskell-beginners] Continuations Message-ID: Hi, Reading on continuation I've came across this new style of creating the functions which I guess is not very clear in how it works --------------- Prelude> let add_cps x y = \k -> k (x+y) Prelude> add_cps 3 4 $ print 7 --------------- I have some questions as to 1) what is the role of variable 'k' and what eventually happens to it. 2) How does print work after the $ because there is clearly no parameter being passed to it. Thanks, Shishir Srivastava -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Thu May 28 16:58:47 2015 From: toad3k at gmail.com (David McBride) Date: Thu, 28 May 2015 12:58:47 -0400 Subject: [Haskell-beginners] Continuations In-Reply-To: References: Message-ID: \k -> k (x + y) is equivalent to blah k = k (x + y) Except for the fact that you have no function name to work with, which is why it is called an anonymous function (or lambda). You can use it anywhere in your code without having to bother create a named function. On Thu, May 28, 2015 at 9:57 AM, Shishir Srivastava < shishir.srivastava at gmail.com> wrote: > Hi, > > Reading on continuation I've came across this new style of creating the > functions which I guess is not very clear in how it works > > --------------- > Prelude> let add_cps x y = \k -> k (x+y) > Prelude> add_cps 3 4 $ print > 7 > --------------- > > I have some questions as to > 1) what is the role of variable 'k' and what eventually happens to it. > 2) How does print work after the $ because there is clearly no parameter > being passed to it. > > Thanks, > Shishir Srivastava > > > _______________________________________________ > 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 amy at nualeargais.ie Thu May 28 17:17:11 2015 From: amy at nualeargais.ie (Amy de =?utf-8?b?QnVpdGzDqWly?=) Date: Thu, 28 May 2015 17:17:11 +0000 (UTC) Subject: [Haskell-beginners] Continuations References: Message-ID: Hi Shishir, Let's first consider a more straightforward version of the function. ?> let add_cps x y k = k (x+y) So add_cps is a function of x, y, and k, where k is a function that will be applied to x+y. Effectively it converts a function (k) of one argument into a function that takes two arguments. Let's examine the type signature. Now, k could be any function that takes one variable. Why don't we try "print"? In the next example, x=3, y=4, and k=print. What do we expect add_cps to do with those arguments? Well, it should apply the function k (which is "print") to the argument x+y. ?> add_cps 3 4 print 7 And that's what it does! Remember how partial application works? What would happen if we invoke add_cps, but leave out the final argument? The result is a function. That function has no name, and we can't print it, but we can look at its type signature. ?> :t add_cps 3 4 add_cps 3 4 ? Num a ? (a ? t) ? t So this unnamed function takes another function of type a ? t, and returns a function of type t. Effectively it converts a function of one argument into a function that takes two arguments. Let's try that with "print". ?> let f = add_cps 3 4 ?> f print 7 This leads us to an equivalent way to write add_cps: ?> let add_cps x y = \k -> k (x+y) This is identical to the first definition, even though it looks very different! Can you see why? From dan9131 at gmail.com Wed May 27 07:01:43 2015 From: dan9131 at gmail.com (Dananji Liyanage) Date: Wed, 27 May 2015 12:31:43 +0530 Subject: [Haskell-beginners] Working with Haskell matrices Message-ID: Hi All, I'm implementing a puzzle where the input is given as a matrix, using Data.Matrix package in Haskell. How do I implement similar functions to `union`, which are available for lists on a matrix? -- Regards, Dananji Liyanage -------------- next part -------------- An HTML attachment was scrubbed... URL: From jonathan.skarstedt at gmail.com Mon May 25 15:49:52 2015 From: jonathan.skarstedt at gmail.com (=?UTF-8?Q?Jonathan_Sk=C3=A5rstedt?=) Date: Mon, 25 May 2015 17:49:52 +0200 Subject: [Haskell-beginners] Using IO values for computations In-Reply-To: References: Message-ID: When you do computations involving IO, you want to be in IO context. For instance, let's say we want to count the amount of rows in a file, and we're going to use readFile for this First, lets look at the types readFile :: FilePath -> IO String This is a computation with an IO result, which means we should only access it by IO actions. computeLines :: String -> Int computeLines = length . lines Lines is an example computation for calculating the amount of lines in a file. It's composed of the function lines :: String -> [String] which splits a string into a list of strings, divided by line break. This is the function we want to use the result of readFile on, but as it's IO, the type system won't let us. However, there's hope still countLines :: FilePath -> IO Int countLines fp = do file <- readFile fp return $ computeLines file By the powers of the do notation and IO actions we can compose the functions and still live in the comfortable context of IO actions. If you're not used to IO computations, this snippet will contain some concepts that probably are new to you: * The "do" notation; it's a syntactic sugar for doing sequential computations within a type, like IO actions. * The left pointing arrow (<-) is a type-safe way to extract a contextual value (like IO String) into a computable value (like String). * return packages a computation (like Int) into a contextual value (like IO Int). So what we do is fetching the result from readFile with <-, computes it (computeLines file) and package it from an Int to an IO Int. Best regards, Jonathan 2015-05-25 14:29 GMT+02:00 Magnus Therning : > On 25 May 2015 at 08:44, Dananji Liyanage wrote: > > Hi All, > > > > I'm writing a code, where the input is read from a text file using: > > readValues = readFile "Input.txt" > > > > Since the type of this is 'IO String', I can't use this in the consequent > > functions. > > > > For an example: I want to split this as follows within another function > > > > extractInput url method template > > | isURI url == True = getList values components > > | otherwise = [] > > where components = splitTemplate readValues > > values = getURL (splitURL url) method > > > > This gives the following error: > > > > Couldn't match type ?IO String? with ?[Char]? > > Expected type: String > > Actual type: IO String > > > > How can I solve this? > > Start with reading some basic Haskell book/tutorial. That should tell > you how to e.g. use 'do' notation, or `liftM`, to achieve what you > want. > > /M > > -- > Magnus Therning OpenPGP: 0xAB4DFBA4 > email: magnus at therning.org jabber: magnus at therning.org > twitter: magthe http://therning.org/magnus > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Jonathan Sk?rstedt Bergsg?rdsg?rdet 39 Lgh 1108 424 32 G?teborg Mobil: 073 - 76 20 20 7 -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan9131 at gmail.com Wed May 27 08:15:13 2015 From: dan9131 at gmail.com (Dananji Liyanage) Date: Wed, 27 May 2015 13:45:13 +0530 Subject: [Haskell-beginners] Data.Vector in Haskell Message-ID: Hi All, I'm trying to extract elements from a Vector using 'head' and 'tail' function in Data.Vector package, but it gives me the following error now. :41:18: Couldn't match expected type ?Data.Vector.Vector a? with actual type ?vector-0.10.9.1:Data.Vector.Vector Int? NB: ?Data.Vector.Vector? is defined in ?Data.Vector? in package ?vector-0.10.12.3? ?vector-0.10.9.1:Data.Vector.Vector? is defined in ?Data.Vector? in package ?vector-0.10.9.1? Relevant bindings include it :: a (bound at :41:1) In the first argument of ?Data.Vector.head?, namely ?it? In the expression: Data.Vector.head it It was working fine before. Any help would be appreciated. Thanks in advance! -- Regards, Dananji Liyanage -------------- next part -------------- An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Thu May 28 21:01:54 2015 From: allbery.b at gmail.com (Brandon Allbery) Date: Thu, 28 May 2015 17:01:54 -0400 Subject: [Haskell-beginners] Data.Vector in Haskell In-Reply-To: References: Message-ID: On Wed, May 27, 2015 at 4:15 AM, Dananji Liyanage wrote: > :41:18: > Couldn't match expected type ?Data.Vector.Vector a? > with actual type ?vector-0.10.9.1:Data.Vector.Vector Int? > NB: ?Data.Vector.Vector? > is defined in ?Data.Vector? in package ?vector-0.10.12.3? > ?vector-0.10.9.1:Data.Vector.Vector? > is defined in ?Data.Vector? in package ?vector-0.10.9.1? > Did you read the message? It is telling you that you have two versions of the vector package installed, and it is unable to reconcile them. You should likely remove one of them --- and in the future use sandboxes so that you can avoid this kind of conflict. -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From cma at bitemyapp.com Thu May 28 21:03:42 2015 From: cma at bitemyapp.com (Christopher Allen) Date: Thu, 28 May 2015 16:03:42 -0500 Subject: [Haskell-beginners] Data.Vector in Haskell In-Reply-To: References: Message-ID: To that end, I've got an example for firing up a little Cabal project and using a sandbox for the dependencies here: http://howistart.org/posts/haskell/1 The short version: mkdir project && cd project && cabal sandbox init && cabal install vector && cabal repl Hope this helps, Chris On Thu, May 28, 2015 at 4:01 PM, Brandon Allbery wrote: > On Wed, May 27, 2015 at 4:15 AM, Dananji Liyanage > wrote: > >> :41:18: >> Couldn't match expected type ?Data.Vector.Vector a? >> with actual type ?vector-0.10.9.1:Data.Vector.Vector Int? >> NB: ?Data.Vector.Vector? >> is defined in ?Data.Vector? in package ?vector-0.10.12.3? >> ?vector-0.10.9.1:Data.Vector.Vector? >> is defined in ?Data.Vector? in package ?vector-0.10.9.1? >> > > Did you read the message? It is telling you that you have two versions of > the vector package installed, and it is unable to reconcile them. > > You should likely remove one of them --- and in the future use sandboxes > so that you can avoid this kind of conflict. > > -- > brandon s allbery kf8nh sine nomine > associates > allbery.b at gmail.com > ballbery at sinenomine.net > unix, openafs, kerberos, infrastructure, xmonad > http://sinenomine.net > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bdezonia at gmail.com Mon May 25 17:42:35 2015 From: bdezonia at gmail.com (Barry DeZonia) Date: Mon, 25 May 2015 12:42:35 -0500 Subject: [Haskell-beginners] Can't figure out my error here Message-ID: Hello, I have a small piece of code that does not compile and I'm having trouble figuring out why. Here is the relevant snippet: readChunks :: Handle -> [String] -> IO [String] readChunks handle accum = do chunk <- readHeaderChunk handle if isLast chunk then return (accum ++ chunk) else return (readChunks handle (accum ++ chunk)) isLast :: [String] -> Bool readHeaderChunk :: Handle -> IO [String] And here is the single compiler error: hacks.hs:48:18: Couldn't match expected type `[String]' with actual type `IO [String]' In the return type of a call of `readChunks' In the first argument of `return', namely `(readChunks handle (accum ++ chunk))' In the expression: return (readChunks handle (accum ++ chunk)) What I'm most confused about is that chunk is passed to isLast as a [String] with no compiler error but cannot be passed to accum ++ chunk that way. Or so it seems. Can someone she some light on this? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwm at mired.org Thu May 28 21:13:25 2015 From: mwm at mired.org (Mike Meyer) Date: Thu, 28 May 2015 16:13:25 -0500 Subject: [Haskell-beginners] Can't figure out my error here In-Reply-To: References: Message-ID: readChunks is already in the IO context, so return (which, confusingly, is not a keyword to return a value from a function, but a function that puts a value back in a context) in the last line of readChunks needs to be deleted. On Mon, May 25, 2015 at 12:42 PM, Barry DeZonia wrote: > Hello, > > I have a small piece of code that does not compile and I'm having trouble > figuring out why. > > Here is the relevant snippet: > > readChunks :: Handle -> [String] -> IO [String] > readChunks handle accum = do > chunk <- readHeaderChunk handle > if isLast chunk > then return (accum ++ chunk) > else return (readChunks handle (accum ++ chunk)) > > isLast :: [String] -> Bool > > readHeaderChunk :: Handle -> IO [String] > > And here is the single compiler error: > > hacks.hs:48:18: > Couldn't match expected type `[String]' > with actual type `IO [String]' > In the return type of a call of `readChunks' > In the first argument of `return', namely > `(readChunks handle (accum ++ chunk))' > In the expression: return (readChunks handle (accum ++ chunk)) > > What I'm most confused about is that chunk is passed to isLast as a > [String] with no compiler error but cannot be passed to accum ++ chunk that > way. Or so it seems. Can someone she some light on this? 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 sumit.sahrawat.apm13 at iitbhu.ac.in Thu May 28 21:14:27 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Fri, 29 May 2015 02:44:27 +0530 Subject: [Haskell-beginners] Can't figure out my error here In-Reply-To: References: Message-ID: On 25 May 2015 at 23:12, Barry DeZonia wrote: > Hello, > > I have a small piece of code that does not compile and I'm having trouble > figuring out why. > > Here is the relevant snippet: > > readChunks :: Handle -> [String] -> IO [String] > readChunks handle accum = do > chunk <- readHeaderChunk handle > if isLast chunk > then return (accum ++ chunk) > else return (readChunks handle (accum ++ chunk)) > In short, try: else readChunks handle (accum ++ chunk) Explanation, return :: a -> IO a (in this case) readChunks handle (accum ++ chunk) :: IO [String] therefore, return (readChunks handle (accum ++ chunk)) :: IO (IO [String]) > isLast :: [String] -> Bool > > readHeaderChunk :: Handle -> IO [String] > > And here is the single compiler error: > > hacks.hs:48:18: > Couldn't match expected type `[String]' > with actual type `IO [String]' > Wanted [String], got IO [String] In the return type of a call of `readChunks' > In the first argument of `return', namely > `(readChunks handle (accum ++ chunk))' > In the expression: return (readChunks handle (accum ++ chunk)) > > What I'm most confused about is that chunk is passed to isLast as a > [String] with no compiler error but cannot be passed to accum ++ chunk that > way. Or so it seems. Can someone she some light on this? Thanks. > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From briand at aracnet.com Fri May 29 03:53:26 2015 From: briand at aracnet.com (briand at aracnet.com) Date: Thu, 28 May 2015 20:53:26 -0700 Subject: [Haskell-beginners] Data.Vector in Haskell In-Reply-To: References: Message-ID: <20150528205326.03855979@cedar.deldotd.com> On Thu, 28 May 2015 16:03:42 -0500 Christopher Allen wrote: > To that end, I've got an example for firing up a little Cabal project and > using a sandbox for the dependencies here: > http://howistart.org/posts/haskell/1 > > The short version: > > mkdir project && cd project && cabal sandbox init && cabal install vector > && cabal repl > very nice. i've bookmarked it!! Brian From joel.neely at gmail.com Fri May 29 12:15:27 2015 From: joel.neely at gmail.com (Joel Neely) Date: Fri, 29 May 2015 07:15:27 -0500 Subject: [Haskell-beginners] Continuations In-Reply-To: References: Message-ID: Shishir, You've already gotten some excellent descriptions. As a recovering OO programmer, I get to the same answer by a slightly different path, offered below for what it's worth. When I read the first line: let add_cps x y = \k -> k (x+y) I see a definition of a function (add_cps) with two arguments (x and y) whose evaluation yields a function (\k -> k (x+y)). *I started to write "an anonymous function" out of habit, but stopped myself. I don't think of functions as having names or not having names, any more than I think of expressions as having names or not. Variables are bound to (refer to) values, and a function is just another kind of value to which a variable can refer. (And multiple variables can refer to the same value, by the way, so none of them is really "the name" of the value, regardless of whether that value happens to be a function.)* So at this point, I can think of using the name add_cps in another expression, such as: add_cps 3 4 which (by the substitution principle) must be equivalent to: \k -> k (3+4) That expression is clearly a function (because of the lambda) that takes a single argument and applies it to the expression (3+4) (which isn't yet evaluated, by the way, but when it is I expect it to yield 7). So the argument to that function expression must itself be a function. When I get to the second line: add_cps 3 4 $ print I confess to cheating a bit (and the experts may want to offer me some correction). I mentally rewrite that as: (add_cps 3 4) print because the precedence rules tell me to evaluate the left argument of $ before combining that with what follows. So I can apply the substitution principle to get (\k -> k (3+4)) print and then apply it again to get print (3+4) Hope this helps, -jn- On Thu, May 28, 2015 at 8:57 AM, Shishir Srivastava < shishir.srivastava at gmail.com> wrote: > Hi, > > Reading on continuation I've came across this new style of creating the > functions which I guess is not very clear in how it works > > --------------- > Prelude> let add_cps x y = \k -> k (x+y) > Prelude> add_cps 3 4 $ print > 7 > --------------- > > I have some questions as to > 1) what is the role of variable 'k' and what eventually happens to it. > 2) How does print work after the $ because there is clearly no parameter > being passed to it. > > Thanks, > Shishir Srivastava > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Beauty of style and harmony and grace and good rhythm depend on simplicity. - Plato -------------- next part -------------- An HTML attachment was scrubbed... URL: From shishir.srivastava at gmail.com Fri May 29 12:26:13 2015 From: shishir.srivastava at gmail.com (Shishir Srivastava) Date: Fri, 29 May 2015 13:26:13 +0100 Subject: [Haskell-beginners] Continuations Message-ID: Hi Amy Thanks for explanation. Yes I can now see that equivalence relation between your example and mine. It does sometime feel alien to see variables representing partially applied functions (e.g k in this case) when you are coming from the imperative land. Cheers, Shishir Srivastava -------------- next part -------------- An HTML attachment was scrubbed... URL: From mihai.maruseac at gmail.com Fri May 29 20:41:56 2015 From: mihai.maruseac at gmail.com (Mihai Maruseac) Date: Fri, 29 May 2015 16:41:56 -0400 Subject: [Haskell-beginners] ANNOUNCE: Haskell Communities and Activities Report (28th ed., May 2015) Message-ID: On behalf of all the contributors, we are pleased to announce that the Haskell Communities and Activities Report (28th edition, May 2014) is now available, in PDF and HTML formats: http://haskell.org/communities/05-2015/report.pdf http://haskell.org/communities/05-2015/html/report.html Many thanks go to all the people that contributed to this report, both directly, by sending in descriptions, and indirectly, by doing all the interesting things that are reported. We hope you will find it as interesting a read as we did. If you have not encountered the Haskell Communities and Activities Reports before, you may like to know that the first of these reports was published in November 2001. Their goal is to improve the communication between the increasingly diverse groups, projects, and individuals working on, with, or inspired by Haskell. The idea behind these reports is simple: Every six months, a call goes out to all of you enjoying Haskell to contribute brief summaries of your own area of work. Many of you respond (eagerly, unprompted, and sometimes in time for the actual deadline) to the call. The editors collect all the contributions into a single report and feed that back to the community. When we try for the next update, six months from now, you might want to report on your own work, project, research area or group as well. So, please put the following into your diaries now: ======================================== End of September 2015: target deadline for contributions to the November 2015 edition of the HC&A Report ======================================== Unfortunately, many Haskellers working on interesting projects are so busy with their work that they seem to have lost the time to follow the Haskell related mailing lists and newsgroups, and have trouble even finding time to report on their work. If you are a member, user or friend of a project so burdened, please find someone willing to make time to report and ask them to "register" with the editors for a simple e-mail reminder in October (you could point us to them as well, and we can then politely ask if they want to contribute, but it might work better if you do the initial asking). Of course, they will still have to find the ten to fifteen minutes to draw up their report, but maybe we can increase our coverage of all that is going on in the community. Feel free to circulate this announcement further in order to reach people who might otherwise not see it. Enjoy! Mihai Maruseac and Alejandro Serrano Mena -- Mihai Maruseac (MM) "If you can't solve a problem, then there's an easier problem you can solve: find it." -- George Polya -------------- next part -------------- An HTML attachment was scrubbed... URL: From briand at aracnet.com Sun May 31 01:30:44 2015 From: briand at aracnet.com (briand at aracnet.com) Date: Sat, 30 May 2015 18:30:44 -0700 Subject: [Haskell-beginners] best way to code this Message-ID: <20150530183044.400cb10b@cedar.deldotd.com> Hi, A simple example of something I was trying to do but it had some questions along the lines of "the best way to do this". Given a list l = [a] and an a-list alist = [ (a,b) ] the idea is to find all the items in l which are in alist and then create a list [b] so the overall function should be [a] -> [ (a,b) ] -> [b] the solution is straightforward: l1 = filter (\x -> isJust (lookup x alist)) l l2 = map (\x -> fromJust (lookup x alist)) l1 `fromJust` used in the construction of l2 won't fail, because only the elements for which the lookup succeeded are in l1. This would be something called `filterMap` but I couldn't find such a function in the list library, but it seems like there just has to be one defined in a library somewhere. the above seems clumsy, i'm wondering how to make it "more pretty". generally i was also wondering if the above construction is as inefficient as it looks because of the double-lookup, or would the compiler actually be able to optimize that code into something more efficient ? this code is not being used on large sets of data so efficiency doesn't matter, I'm just curious. Thanks, Brian From maydwell at gmail.com Sun May 31 01:47:01 2015 From: maydwell at gmail.com (Lyndon Maydwell) Date: Sun, 31 May 2015 11:47:01 +1000 Subject: [Haskell-beginners] best way to code this In-Reply-To: <20150530183044.400cb10b@cedar.deldotd.com> References: <20150530183044.400cb10b@cedar.deldotd.com> Message-ID: I think you're looking for `mapMaybe` :-) - Lyndon On Sun, May 31, 2015 at 11:30 AM, wrote: > Hi, > > A simple example of something I was trying to do but it had some questions > along the lines of "the best way to do this". > > Given a list > > l = [a] > > and an a-list > > alist = [ (a,b) ] > > the idea is to find all the items in l which are in alist and then create > a list [b] > > so the overall function should be > > [a] -> [ (a,b) ] -> [b] > > the solution is straightforward: > > l1 = filter (\x -> isJust (lookup x alist)) l > l2 = map (\x -> fromJust (lookup x alist)) l1 > > `fromJust` used in the construction of l2 won't fail, because only the > elements for which the lookup succeeded are in l1. > > This would be something called `filterMap` but I couldn't find such a > function in the list library, but it seems like there just has to be one > defined in a library somewhere. > > the above seems clumsy, i'm wondering how to make it "more pretty". > > generally i was also wondering if the above construction is as inefficient > as it looks because of the double-lookup, or would the compiler actually be > able to optimize that code into something more efficient ? this code is > not being used on large sets of data so efficiency doesn't matter, I'm just > curious. > > Thanks, > > Brian > _______________________________________________ > 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 briand at aracnet.com Sun May 31 05:14:44 2015 From: briand at aracnet.com (briand at aracnet.com) Date: Sat, 30 May 2015 22:14:44 -0700 Subject: [Haskell-beginners] best way to code this In-Reply-To: References: <20150530183044.400cb10b@cedar.deldotd.com> Message-ID: <20150530221444.6e81f367@cedar.deldotd.com> On Sun, 31 May 2015 11:47:01 +1000 Lyndon Maydwell wrote: > I think you're looking for `mapMaybe` :-) > > yes. yes i am. lol. i even had the Maybe module open and just didn't get all the way to the end. although after looking at my problem, i realized i need to save those elements of the list that weren't matched. that makes it slightly more complicated. but i did find partition which works nicely. thanks! Brian From ahammel87 at gmail.com Sun May 31 05:17:10 2015 From: ahammel87 at gmail.com (Alex Hammel) Date: Sun, 31 May 2015 05:17:10 +0000 Subject: [Haskell-beginners] best way to code this In-Reply-To: References: <20150530183044.400cb10b@cedar.deldotd.com> Message-ID: f as alist = [ b | (a, b) <- alist, a `elem` as ] perhaps? On Sat, 30 May 2015 6:47 pm Lyndon Maydwell wrote: > I think you're looking for `mapMaybe` :-) > > > - Lyndon > > On Sun, May 31, 2015 at 11:30 AM, wrote: > >> Hi, >> >> A simple example of something I was trying to do but it had some >> questions along the lines of "the best way to do this". >> >> Given a list >> >> l = [a] >> >> and an a-list >> >> alist = [ (a,b) ] >> >> the idea is to find all the items in l which are in alist and then create >> a list [b] >> >> so the overall function should be >> >> [a] -> [ (a,b) ] -> [b] >> >> the solution is straightforward: >> >> l1 = filter (\x -> isJust (lookup x alist)) l >> l2 = map (\x -> fromJust (lookup x alist)) l1 >> >> `fromJust` used in the construction of l2 won't fail, because only the >> elements for which the lookup succeeded are in l1. >> >> This would be something called `filterMap` but I couldn't find such a >> function in the list library, but it seems like there just has to be one >> defined in a library somewhere. >> >> the above seems clumsy, i'm wondering how to make it "more pretty". >> >> generally i was also wondering if the above construction is as >> inefficient as it looks because of the double-lookup, or would the compiler >> actually be able to optimize that code into something more efficient ? >> this code is not being used on large sets of data so efficiency doesn't >> matter, I'm just curious. >> >> Thanks, >> >> Brian >> _______________________________________________ >> 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 chaddai.fouche at gmail.com Sun May 31 09:47:50 2015 From: chaddai.fouche at gmail.com (=?UTF-8?B?Q2hhZGRhw68gRm91Y2jDqQ==?=) Date: Sun, 31 May 2015 09:47:50 +0000 Subject: [Haskell-beginners] best way to code this In-Reply-To: References: <20150530183044.400cb10b@cedar.deldotd.com> Message-ID: Note that all proposed solutions are in O(n?) while this can be realized in O(n log n) (sort both list then match them in order). It depends on your use case if this is worthwhile. -- Jeda? Le dim. 31 mai 2015 ? 07:17, Alex Hammel a ?crit : > f as alist = [ b | (a, b) <- alist, a `elem` as ] > > perhaps? > > On Sat, 30 May 2015 6:47 pm Lyndon Maydwell wrote: > >> I think you're looking for `mapMaybe` :-) >> >> >> - Lyndon >> >> On Sun, May 31, 2015 at 11:30 AM, wrote: >> >>> Hi, >>> >>> A simple example of something I was trying to do but it had some >>> questions along the lines of "the best way to do this". >>> >>> Given a list >>> >>> l = [a] >>> >>> and an a-list >>> >>> alist = [ (a,b) ] >>> >>> the idea is to find all the items in l which are in alist and then >>> create a list [b] >>> >>> so the overall function should be >>> >>> [a] -> [ (a,b) ] -> [b] >>> >>> the solution is straightforward: >>> >>> l1 = filter (\x -> isJust (lookup x alist)) l >>> l2 = map (\x -> fromJust (lookup x alist)) l1 >>> >>> `fromJust` used in the construction of l2 won't fail, because only the >>> elements for which the lookup succeeded are in l1. >>> >>> This would be something called `filterMap` but I couldn't find such a >>> function in the list library, but it seems like there just has to be one >>> defined in a library somewhere. >>> >>> the above seems clumsy, i'm wondering how to make it "more pretty". >>> >>> generally i was also wondering if the above construction is as >>> inefficient as it looks because of the double-lookup, or would the compiler >>> actually be able to optimize that code into something more efficient ? >>> this code is not being used on large sets of data so efficiency doesn't >>> matter, I'm just curious. >>> >>> Thanks, >>> >>> Brian >>> _______________________________________________ >>> 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 briand at aracnet.com Sun May 31 15:02:29 2015 From: briand at aracnet.com (briand at aracnet.com) Date: Sun, 31 May 2015 08:02:29 -0700 Subject: [Haskell-beginners] best way to code this~~ In-Reply-To: References: <20150530183044.400cb10b@cedar.deldotd.com> Message-ID: <20150531080229.5e520739@cedar.deldotd.com> On Sun, 31 May 2015 05:17:10 +0000 Alex Hammel wrote: > f as alist = [ b | (a, b) <- alist, a `elem` as ] > > perhaps? perhaps. i have no idea how that works. but don't spoil it for me though, i'm going to go of and study it :-) @Chaddai . this is for very small lists, so optimization in the form of sorting and binary lookup is definitely not worth the effort. Here's what I finally wrote. partitionMaybe is a modified version of partition from the List library. unsure what the ~(ts, fs) syntax is though, removing the `~` doesn't seem to matter. this seems fairly clean. i noticed that partition simply uses foldr. it looks like select is just a helper so that partition isn't cluttered. i'm unsure why select was broken out as a separate function instead of just being in a where clause. possibly to be able to assign it a an explicit type signature ? more likely it has something to do with the fact that in the library partition is declared inline. extract :: [(String,b)] -> [String] -> ([b], [String]) extract alist l = let inList s = lookup (uppercase s) alist (l1, l2) = partitionMaybe inList l in (l1, l2) partitionMaybe :: (a -> Maybe b) -> [a] -> ([b],[a]) partitionMaybe p xs = foldr (select p) ([],[]) xs select :: (a -> Maybe b) -> a -> ([b], [a]) -> ([b], [a]) select p x ~(ts,fs) | isJust y = ((fromJust y):ts,fs) | otherwise = (ts, x:fs) where y = p x