Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Functional Parses (Robert Heum?ller) 2. Re: Functional Parses (Robert Heum?ller) 3. Re: Functional Parses (Christian Maeder) 4. Using tls-extra for simple smtp (Sarfraz K.) 5. Re: Functional Parses (Stephen Tetley) 6. Problems with installing lambdabot (Antoras) 7. Re: Problems with installing lambdabot (Brent Yorgey) 8. Re: Help with Why Do Monads Matter blog post understanding (Brent Yorgey) ---------------------------------------------------------------------- Message: 1 Date: Tue, 3 Jul 2012 15:08:37 +0200 From: Robert Heum?ller <mail...@heum.de> Subject: [Haskell-beginners] Functional Parses To: beginners@haskell.org Message-ID: <20120703150837.34989630@thor> Content-Type: text/plain; charset=US-ASCII Hi again, currently I'm trying to figure out how to properly write a parser in haskell. I've been following the instructions in a book called "Programming in Haskell" by Graham Hutton. So far I've written the following: ------------------------------ Message: 2 Date: Tue, 3 Jul 2012 15:16:02 +0200 From: Robert Heum?ller <mail...@heum.de> Subject: Re: [Haskell-beginners] Functional Parses To: beginners@haskell.org Message-ID: <20120703151602.02384728@thor> Content-Type: text/plain; charset=US-ASCII I am sorry, I must have hit the wrong hotkey. My code looks like this: type Parser a = String -> [(a, String)] result :: a -> Parser a result v = \inp -> [(v, inp)] zero :: Parser a zero = \inp -> [] item :: Parser Char item = \inp -> case inp of [] -> [] (x:xs) -> [(x, xs)] parse :: Parser a -> String -> [(a, String)] parse p inp = p inp (>>=) :: Parser a -> (a -> Parser b) -> Parser b (>>=) p f = \inp -> concat [f v inp' | (v, inp') <- p inp] sat :: (Char -> Bool) -> Parser Char sat p = do x <- item if p x then result x else zero I beleive I understand how this code is meant to work, but when I run it in ghci I get the follwing error-message: parser.hs:21:13: No instance for (Monad ((->) String)) arising from a do statement Possible fix: add an instance declaration for (Monad ((->) String)) In a stmt of a 'do' block: x <- item In the expression: do { x <- item; if p x then result x else zero } In an equation for `sat': sat p = do { x <- item; if p x then result x else zero } parser.hs:22:18: Couldn't match expected type `Char' with actual type `[(Char, String)]' In the first argument of `p', namely `x' In the expression: p x In a stmt of a 'do' block: if p x then result x else zero Failed, modules loaded: none. Sadly I have no idea how to fix this :( Thanks again :) ------------------------------ Message: 3 Date: Tue, 03 Jul 2012 16:13:50 +0200 From: Christian Maeder <christian.mae...@dfki.de> Subject: Re: [Haskell-beginners] Functional Parses To: Robert Heum?ller <mail...@heum.de> Cc: beginners@haskell.org Message-ID: <4ff2fe1e.1040...@dfki.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Am 03.07.2012 15:16, schrieb Robert Heum?ller: > I am sorry, I must have hit the wrong hotkey. > My code looks like this: > > type Parser a = String -> [(a, String)] This type synonym is unsuitable for a Monad instance. Better would be: newtype Parser a = Parser (String -> [(a, String)]) but that would require to change your code below. > > result :: a -> Parser a > result v = \inp -> [(v, inp)] > > zero :: Parser a > zero = \inp -> [] > > item :: Parser Char > item = \inp -> case inp of > [] -> [] > (x:xs) -> [(x, xs)] > > parse :: Parser a -> String -> [(a, String)] > parse p inp = p inp > > (>>=) :: Parser a -> (a -> Parser b) -> Parser b > (>>=) p f = \inp -> concat [f v inp' | (v, inp') <- p inp] Such a definition (without signature and adapted to the newtype) should be used within a Monad instance. "instance Monad Parser where ..." > sat :: (Char -> Bool) -> Parser Char > sat p = do x <- item > if p x then result x else zero Without proper Monad instance you should not use "do". Instead you could expand it yourself manually to: sat p = item Main.>>= \x -> if p x then result x else zero Note the clash between your ">>=" function (Main.>>=) and the one from the Prelude! HTH Christian P.S. there is a "instance Monad ((->) r))" in Control.Monad.Instances but that does not fit your parser type, too. > > > I beleive I understand how this code is meant to work, but when I run > it in ghci I get the follwing error-message: > > parser.hs:21:13: > No instance for (Monad ((->) String)) > arising from a do statement > Possible fix: add an instance declaration for (Monad ((->) String)) > In a stmt of a 'do' block: x <- item > In the expression: > do { x <- item; > if p x then result x else zero } > In an equation for `sat': > sat p > = do { x <- item; > if p x then result x else zero } > > parser.hs:22:18: > Couldn't match expected type `Char' > with actual type `[(Char, String)]' > In the first argument of `p', namely `x' > In the expression: p x > In a stmt of a 'do' block: if p x then result x else zero > Failed, modules loaded: none. > > > Sadly I have no idea how to fix this :( > > Thanks again :) > ------------------------------ Message: 4 Date: Tue, 3 Jul 2012 17:16:37 +0200 From: "Sarfraz K." <dragoon.emp...@yahoo.fr> Subject: [Haskell-beginners] Using tls-extra for simple smtp To: beginners@haskell.org Message-ID: <20120703151637.GA6053@univers> Content-Type: text/plain; charset="us-ascii" I am trying to write a simple script to send a mail via my gmail account. But I am a beginner so it is not that simple. I tryed google but exept for hackage, there is no help or examples at all. The problem is that I did not find the way to use tls-extra(or tls) to initiate the STARTTLS exchange. Ok, here is the code: import Network import Network.TLS.Extra import System.IO import Text.Printf server = "smtp.gmail.com" port = 25 --that has to chage, I think forever a = a >> forever a main = test1 write :: Handle -> String -> IO () write h s = do hPrintf h "%s\r\n" s printf "> %s\n" s listen :: Handle -> IO () listen h = forever $ hGetLine h >>= putStrLn test1 = do h <- connectTo server (PortNumber (fromIntegral port)) hSetBuffering h NoBuffering write h "EHLO" write h "STATTLS" listen h Another thing is that I use the listen function to know what is going on. But I cannot figure out how to use it along with write. That is to say, I would like to be able to see what is going on server-side while sending some data. I found two functions that may resolve my problems: connectionClient :: CryptoRandomGen g => String -> String -> TLSParams -> g -> IO (TLSCtx Handle) forkIO :: IO () -> IO ThreadId The first for tls and the second to send and receive at the same time. But can't seem to make them work. I hope I am not to messy here, any help would be appreciated. PS: English is not my native. -- Sarfraz K. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: not available URL: <http://www.haskell.org/pipermail/beginners/attachments/20120703/38a89389/attachment-0001.pgp> ------------------------------ Message: 5 Date: Tue, 3 Jul 2012 18:01:32 +0100 From: Stephen Tetley <stephen.tet...@gmail.com> Subject: Re: [Haskell-beginners] Functional Parses Cc: beginners@haskell.org Message-ID: <cab2tprce-4v1hnydxhvd_9ekee54ou7wrtek2kvhqrrpgdh...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 On 3 July 2012 15:13, Christian Maeder <christian.mae...@dfki.de> wrote: > This type synonym is unsuitable for a Monad instance. > Better would be: > newtype Parser a = Parser (String -> [(a, String)]) > but that would require to change your code below. This is alluded to in the closing chapter remarks (section 8.9) of Graham Hutton's book and there is code available on the website that accompanies the book that "solves" the problem. Unfortunately, this chapter does seem to trip people up who use the book for self study. ------------------------------ Message: 6 Date: Tue, 03 Jul 2012 21:16:00 +0200 From: Antoras <m...@antoras.de> Subject: [Haskell-beginners] Problems with installing lambdabot To: beginners@haskell.org Message-ID: <4ff344f0.60...@antoras.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed I tried to install labdabot with 'cabal install lambdabot' and after some minutes cabal aborts with an error message (see end of mail). I use ArchLinux 64Bit and the following software versions: $ cabal -V cabal-install version 0.14.0 using version 1.14.0 of the Cabal library $ ghc --version The Glorious Glasgow Haskell Compilation System, version 7.4.2 $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/lto-wrapper Target: x86_64-unknown-linux-gnu [...] gcc version 4.7.1 (GCC) Does someone know what's the problem here? Error message: $ cabal install lambdabot Resolving dependencies... Configuring lambdabot-4.2.3.2... Building lambdabot-4.2.3.2... Preprocessing executable 'lambdabot' for lambdabot-4.2.3.2... [...] [28 of 79] Compiling Plugin.Activity ( Plugin/Activity.hs, dist/build/lambdabot/lambdabot-tmp/Plugin/Activity.o ) Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Loading package Boolean-0.0.1 ... linking ... done. Loading package array-0.4.0.0 ... linking ... done. Loading package deepseq-1.3.0.0 ... linking ... done. Loading package containers-0.4.2.1 ... linking ... done. Loading package semigroups-0.8.3.2 ... linking ... done. Loading package void-0.5.6 ... linking ... done. Loading package MemoTrie-0.5 ... linking ... done. Loading package NumInstances-1.0 ... linking ... done. Loading package vector-space-0.8.1 ... linking ... done. Loading package transformers-0.3.0.0 ... linking ... done. Loading package mtl-2.1.2 ... linking ... done. Loading package bytestring-0.9.2.1 ... linking ... done. Loading package unix-2.5.1.1 ... linking ... done. Loading package unlambda-0.1 ... linking ... done. Loading package extensible-exceptions-0.1.1.4 ... linking ... done. Loading package old-locale-1.0.0.4 ... linking ... done. Loading package time-1.4 ... linking ... done. Loading package random-1.0.1.1 ... linking ... done. Loading package pretty-1.1.1.0 ... linking ... done. Loading package template-haskell ... linking ... done. Loading package QuickCheck-2.5 ... linking ... done. Loading package dlist-0.5 ... linking ... done. Loading package smallcheck-0.6.1 ... linking ... done. Loading package syb-0.3.6.2 ... linking ... done. Loading package show-0.4.1.2 ... linking ... done. Loading package filepath-1.3.0.0 ... linking ... done. Loading package old-time-1.1.0.0 ... linking ... done. Loading package directory-1.1.0.2 ... linking ... done. Loading package process-1.1.0.1 ... linking ... done. Loading package readline-1.0.1.0 ... <command line>: can't load .so/.DLL for: /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../lib/libncurses.so (-lncursesw: cannot open shared object file: No such file or directory) cabal: Error: some packages failed to install: lambdabot-4.2.3.2 failed during the building phase. The exception was: ExitFailure 1 cabal install lambdabot 15.19s user 0.67s system 96% cpu 16.413 total ------------------------------ Message: 7 Date: Tue, 3 Jul 2012 15:40:38 -0400 From: Brent Yorgey <byor...@seas.upenn.edu> Subject: Re: [Haskell-beginners] Problems with installing lambdabot To: beginners@haskell.org Message-ID: <20120703194038.ga...@seas.upenn.edu> Content-Type: text/plain; charset=us-ascii This particular error appears to have something to do with your ncurses installation (do you have ncurses installed?). However, I should warn you that lambdabot is notoriously difficult to install. -Brent On Tue, Jul 03, 2012 at 09:16:00PM +0200, Antoras wrote: > I tried to install labdabot with 'cabal install lambdabot' and after > some minutes cabal aborts with an error message (see end of mail). > > I use ArchLinux 64Bit and the following software versions: > > $ cabal -V > cabal-install version 0.14.0 > using version 1.14.0 of the Cabal library > $ ghc --version > The Glorious Glasgow Haskell Compilation System, version 7.4.2 > $ gcc -v > Using built-in specs. > COLLECT_GCC=gcc > COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/lto-wrapper > Target: x86_64-unknown-linux-gnu > [...] > gcc version 4.7.1 (GCC) > > Does someone know what's the problem here? > > > Error message: > > > $ cabal install lambdabot > Resolving dependencies... > Configuring lambdabot-4.2.3.2... > Building lambdabot-4.2.3.2... > Preprocessing executable 'lambdabot' for lambdabot-4.2.3.2... > > [...] > > [28 of 79] Compiling Plugin.Activity ( Plugin/Activity.hs, > dist/build/lambdabot/lambdabot-tmp/Plugin/Activity.o ) > Loading package ghc-prim ... linking ... done. > Loading package integer-gmp ... linking ... done. > Loading package base ... linking ... done. > Loading package Boolean-0.0.1 ... linking ... done. > Loading package array-0.4.0.0 ... linking ... done. > Loading package deepseq-1.3.0.0 ... linking ... done. > Loading package containers-0.4.2.1 ... linking ... done. > Loading package semigroups-0.8.3.2 ... linking ... done. > Loading package void-0.5.6 ... linking ... done. > Loading package MemoTrie-0.5 ... linking ... done. > Loading package NumInstances-1.0 ... linking ... done. > Loading package vector-space-0.8.1 ... linking ... done. > Loading package transformers-0.3.0.0 ... linking ... done. > Loading package mtl-2.1.2 ... linking ... done. > Loading package bytestring-0.9.2.1 ... linking ... done. > Loading package unix-2.5.1.1 ... linking ... done. > Loading package unlambda-0.1 ... linking ... done. > Loading package extensible-exceptions-0.1.1.4 ... linking ... done. > Loading package old-locale-1.0.0.4 ... linking ... done. > Loading package time-1.4 ... linking ... done. > Loading package random-1.0.1.1 ... linking ... done. > Loading package pretty-1.1.1.0 ... linking ... done. > Loading package template-haskell ... linking ... done. > Loading package QuickCheck-2.5 ... linking ... done. > Loading package dlist-0.5 ... linking ... done. > Loading package smallcheck-0.6.1 ... linking ... done. > Loading package syb-0.3.6.2 ... linking ... done. > Loading package show-0.4.1.2 ... linking ... done. > Loading package filepath-1.3.0.0 ... linking ... done. > Loading package old-time-1.1.0.0 ... linking ... done. > Loading package directory-1.1.0.2 ... linking ... done. > Loading package process-1.1.0.1 ... linking ... done. > Loading package readline-1.0.1.0 ... <command line>: can't load > .so/.DLL for: > /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../lib/libncurses.so > (-lncursesw: cannot open shared object file: No such file or > directory) > cabal: Error: some packages failed to install: > lambdabot-4.2.3.2 failed during the building phase. The exception was: > ExitFailure 1 > cabal install lambdabot 15.19s user 0.67s system 96% cpu 16.413 total > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners ------------------------------ Message: 8 Date: Tue, 3 Jul 2012 15:45:15 -0400 From: Brent Yorgey <byor...@seas.upenn.edu> Subject: Re: [Haskell-beginners] Help with Why Do Monads Matter blog post understanding To: Matt Ford <m...@dancingfrog.co.uk> Cc: beginners@haskell.org Message-ID: <20120703194515.gb...@seas.upenn.edu> Content-Type: text/plain; charset=utf-8 On Fri, Jun 29, 2012 at 09:30:58PM +0100, Matt Ford wrote: > On 29 June 2012 19:52, Brent Yorgey <byor...@seas.upenn.edu> wrote: > > >> "For a set A, we will define the set Pref(A) to be the set of functions > >> from application settings to the set A. Now watch closely: a function in > >> context from A to B is just an ordinary function from A to Pref(B). In > >> other words, you give it a value from the set A, and it gives you back > >> another function that maps from application settings to the set B." > >> > >> This is in the "functioning with dependency" section and is talking about a > >> procedure that uses outside info from preferences or application settings. > >> > >> If I set my prefs as follows > >> > >> configvar = 3 > >> > >> and define a function as follows > >> > >> add x = configvar + 6 > >> > >> So add?s signature is > >> > >> add: int -> int > >> > >> What does prefs(int) look like? Is that even the right thing to ask? > > > > prefs(int) looks like ?Config -> Int (in your example perhaps we > > define ?type Config = Int), so add should have type > > > > ?Int -> (Config -> Int) > > > > The thing that is confusing the issue here is that you just made add > > implicitly use the 'configvar' which is in scope, so it does not need > > to take it as a parameter. > > That's what I'm trying to understand, how we switch from "impure" > functions to "pure" functions which don't rely on external state. > > And I see that passing in functions that act on the state helps do > this. But I don't understand how, for a function that looks like > A->B, that has a whole load dependencies on external variables and > functions (of perhaps lot's of different types) all these variables > and functions are captured by the definition of Pref(B). Well, in that case Pref would have to be some sort of record of all the possible things it could depend on. Note that Pref(A) does *not* mean "the set of functions from *whatever application settings A happens to use* to A". That would not be very useful (and impossible to implement). Rather, one must fix ahead of time what counts as "application settings". Then everything involving Pref will have access to that fixed set of application settings. Does that help at all? > And by changing the actual type of the result of A->B in this case > from an Int to a function that returns an Int how can this hope to > match the original intention of the impure A->B. Say for example > Pref(b) is the empty set as no functions map to from the config to B. > Changing the range means we will never get a sensible result?? I don't think I understand this. Can you give an example? There is definitely something fundamental you are misunderstanding but I am not quite sure what it is. Does my clarification above help at all? -Brent ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 49, Issue 4 ****************************************