Send Beginners mailing list submissions to
[email protected]
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
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Beginners Digest, Vol 7, Issue 24 (Benedikt Ahrens)
2. Re: Help! Trapped in the IO Monad! (Heinrich Apfelmus)
3. Re: Monads... (Cory Knapp)
4. Re: Monads... (Henk-Jan van Tuyl)
5. Question about Real World Haskell (Alan Cameron)
6. Compile type Error (emmanuel.delaborde)
7. Real World Haskell book authors accepting comments?
(Alan Cameron)
8. Re: Compile type Error (Rafael Gustavo da Cunha Pereira Pinto)
----------------------------------------------------------------------
Message: 1
Date: Thu, 29 Jan 2009 11:50:47 +0100
From: Benedikt Ahrens <[email protected]>
Subject: [Haskell-beginners] Re: Beginners Digest, Vol 7, Issue 24
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
hello cory,
you might want to read this article:
http://stefan-klinger.de/files/monadGuide.pdf
it helped me find and understand the monads in haskell.
ben
> Message: 2
> Date: Wed, 28 Jan 2009 20:44:30 -0600
> From: Cory Knapp <[email protected]>
> Subject: [Haskell-beginners] Monads...
> To: [email protected]
> Message-ID: <[email protected]>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Hello, so, I'm having a simple problem with monads: I have no idea how
> to actually use them. I understand the category theory (or, at least
> well enough to be able to explain "what is a monad"); I understand the
> way to declare something as a monad instance, but I just don't get how
> to program with them. Can anyone provide me with, or direct me towards,
> some simple monads and some ways of using (for example) the monadic
> properties of lists?
>
> Thanks,
> Cory
>
------------------------------
Message: 2
Date: Thu, 29 Jan 2009 11:58:51 +0100
From: Heinrich Apfelmus <[email protected]>
Subject: [Haskell-beginners] Re: Help! Trapped in the IO Monad!
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Alexander Dunlap wrote:
> You can do (something like; this is untested)
>
> splitDirFile :: [FilePath] -> IO ([FilePath],[FilePath])
> splitDirFile [] = return ([],[])
> splitDirFile (f:fs) = do
> (yess,nos) <- splitDirFile fs
> exists <- doesDirectoryExist f
> return $ if exists
> then (f:yess,nos)
> else (yess,f:nos)
>
> You might also look at Control.Monad.filterM. I often define a
> function "partitionM" which is like partition except it uses a monadic
> test, just like you have.
How about
splitDirFile ps =
((map fst *** map fst) . partition snd . zip ps)
`liftM` mapM doesDirectoryExist ps
There is no need to rewrite partition , you can reuse it.
Hm, the plumbing seems slightly cumbersome to me, maybe Conal's editor
combinators
http://conal.net/blog/posts/semantic-editor-combinators/
can help.
Regards,
apfelmus
--
http://apfelmus.nfshost.com
------------------------------
Message: 3
Date: Thu, 29 Jan 2009 08:48:42 -0600
From: Cory Knapp <[email protected]>
Subject: Re: [Haskell-beginners] Monads...
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Thanks to both of you, I'll look into those.
Cory
Rafael Gustavo da Cunha Pereira Pinto wrote:
> Cory,
>
> The big hit for me was Phillip Wadler's paper "Monads for functional
> programming" I made me start thinking "well, this looks like a monad..."
>
> homepages.inf.ed.ac.uk/wadler/papers/marktoberdorf/baastad.pdf
> <http://homepages.inf.ed.ac.uk/wadler/papers/marktoberdorf/baastad.pdf>
>
> Cheers
>
> On Thu, Jan 29, 2009 at 01:38, nanothief <[email protected]
> <mailto:[email protected]>> wrote:
>
> Cory Knapp wrote:
>
> Hello, so, I'm having a simple problem with monads: I have no
> idea how to actually use them. I understand the category
> theory (or, at least well enough to be able to explain "what
> is a monad"); I understand the way to declare something as a
> monad instance, but I just don't get how to program with them.
> Can anyone provide me with, or direct me towards, some simple
> monads and some ways of using (for example) the monadic
> properties of lists?
>
> Thanks,
> Cory
> _______________________________________________
> Beginners mailing list
> [email protected] <mailto:[email protected]>
> http://www.haskell.org/mailman/listinfo/beginners
>
> I found that
> http://www.haskell.org/all_about_monads/html/index.html gave a lot
> of nice examples of using list and maybe monads. The list monad is
> particularly useful for finding possible solutions given available
> input values.
> For example, with the problem
> x + 8y = 114
> 3x - 8y + 4z = 182
> x < y < z < 100
> Find solutions for x,y,z
>
> The program:
> res :: [(Int,Int,Int)]
> res = do
> x <- [1..100]
> y <- [1..100]
> z <- [1..100]
> guard $ x + 8 * y == 114
> guard $ 3*x - 8*y + 4*z == 182
> guard $ x < y
> guard $ y < z
> return (x,y,z)
>
> will output all the possible solutions. Note how close the program
> is to the actual problem. The values of x,y, and z are chosen from
> the value [1..100], but if a guard statement fails, the (x,y,z)
> choice is abandoned.
>
> Another example (taken from
> http://www.mathsisfun.com/puzzles/sum-of-digits-is-43-solution.html )
> *The Puzzle:* I am thinking of a 6-digit number. The sum of the
> digits is 43.
>
> And only two of the following three statements about the number
> are true:
>
> (1) it's a square number,
> (2) it's a cube number, and
> (3) the number is under 500000.
>
> the program
> answer = do
> d1 <- [0..9]
> d2 <- [0..9]
> d3 <- [0..9]
> d4 <- [0..9]
> d5 <- [0..9]
> d6 <- [0..9]
> let digitSum = d1 + d2 + d3 + d4 + d5 + d6
> let value = d1 + d2*10 + d3*100 + d4*1000 + d5*10000 + d6*100000
> guard $ digitSum == 43
> let lessThan500000 = digitSum < 500000
> let isSquare = (round $ sqrt (fromIntegral value)) ^ 2 == value
> let isCube = (round $ (fromIntegral value) ** (1/3)) ^ 3 == value
> guard $ length (filter id [lessThan500000,isSquare,isCube]) == 2
> return value
>
> will output the three answers (not that the author only found one
> solution!).
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected] <mailto:[email protected]>
> http://www.haskell.org/mailman/listinfo/beginners
>
>
>
>
> --
> Rafael Gustavo da Cunha Pereira Pinto
> Electronic Engineer, MSc.
------------------------------
Message: 4
Date: Thu, 29 Jan 2009 16:06:07 +0100
From: "Henk-Jan van Tuyl" <[email protected]>
Subject: Re: [Haskell-beginners] Monads...
To: "Cory Knapp" <[email protected]>, [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; format=flowed; delsp=yes;
charset=iso-8859-15
I have written a reference manual for the basic Haskell monad functions,
"A Tour of the Haskell Monad functions". It contains a lot of examples.
You can find it at:
http://members.chello.nl/hjgtuyl/tourdemonad.html
Regards,
Henk-Jan van Tuyl
--
http://functor.bamikanarie.com
http://Van.Tuyl.eu/
--
On Thu, 29 Jan 2009 03:44:30 +0100, Cory Knapp <[email protected]>
wrote:
> Hello, so, I'm having a simple problem with monads: I have no idea how
> to actually use them. I understand the category theory (or, at least
> well enough to be able to explain "what is a monad"); I understand the
> way to declare something as a monad instance, but I just don't get how
> to program with them. Can anyone provide me with, or direct me towards,
> some simple monads and some ways of using (for example) the monadic
> properties of lists?
>
> Thanks,
> Cory
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
--
------------------------------
Message: 5
Date: Thu, 29 Jan 2009 15:21:24 -0000
From: "Alan Cameron" <[email protected]>
Subject: [Haskell-beginners] Question about Real World Haskell
To: <[email protected]>
Message-ID: <c431f46580464bb1bb9e2c2fa1b32...@alanxps>
Content-Type: text/plain; charset="us-ascii"
In Chapter 3 of Real World Haskell it is not clear to me how to get the
myInfo into the ghci system there appears to be two definitions for
ch03/BookStore.hs can anyone help?
Alan Cameron
------------------------------
Message: 6
Date: Thu, 29 Jan 2009 15:25:59 +0000
From: "emmanuel.delaborde" <[email protected]>
Subject: [Haskell-beginners] Compile type Error
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
Hello
I have the following snippet :
----------------------------------------------------------
module Main where
import System.Environment (getArgs)
import Data.Digest.OpenSSL.MD5 (md5sum)
import Data.Digest.Pure.SHA (sha1, showDigest)
import qualified Data.ByteString as BS (readFile)
-- sha1 :: ByteString -> Digest
-- readFile :: FilePath -> IO ByteString
-- md5sum :: ByteString -> String
-- showDigest :: Digest -> String
checkHash :: String -> String -> String -> IO ()
checkHash codec hash file =
let f = case codec of
--"md5" -> md5sum
"sha1" -> showDigest . sha1
_ -> error "Codec must be md5 or sha1 !" in
BS.readFile file >>= \fileBS ->
let fileHash = f fileBS in
print (hash == fileHash)
main =
getArgs >>= \as ->
case as of
(codec:hash:file:_) -> checkHash codec hash file
_ -> usage
usage = print "checksum codec hash file"
----------------------------------------------------------
which fails to compile, this is the error I get :
checksum.hs:20:19:
Couldn't match expected type
`Data.ByteString.Lazy.Internal.ByteString'
against inferred type `Data.ByteString.Internal.ByteString'
In the first argument of `f', namely `fileBS'
In the expression: f fileBS
In the definition of `fileHash': fileHash = f fileBS
it looks like (showDigest . sha1) expects
Data.ByteString.Lazy.Internal.ByteString but gets
Data.ByteString.Internal.ByteString
What can I do ?
Thanks
E.
-----------------------------------------------------------------------------------------------
This e-mail (and any attachments) is confidential and may contain
personal views which are not the views of Cimex Media Ltd and
any affiliated companies, unless specifically stated. It is intended
for the use of the individual or group to whom it is addressed. If
you have received it in error, please delete it from your system,
do not use, copy or disclose the information in any way nor act in
reliance on it and please notify [email protected]
A company registered in England Wales. Company Number 03765711
Registered Office : The Olde Bakehouse, 156 Watling Street East, Towcester,
Northants NN12 6DB
This email was scanned by Postini, the leading provider in Managed Email
Security.
------------------------------
Message: 7
Date: Thu, 29 Jan 2009 15:54:20 -0000
From: "Alan Cameron" <[email protected]>
Subject: [Haskell-beginners] Real World Haskell book authors accepting
comments?
To: <[email protected]>
Message-ID: <a4e979a646454446979d9c91ff2ed...@alanxps>
Content-Type: text/plain; charset="us-ascii"
The online version of the book seems to have stopped accepting comments - at
least from me.
Alan Cameron
------------------------------
Message: 8
Date: Thu, 29 Jan 2009 14:19:38 -0200
From: Rafael Gustavo da Cunha Pereira Pinto
<[email protected]>
Subject: Re: [Haskell-beginners] Compile type Error
To: "emmanuel.delaborde" <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
I didn't compile, but, by the looks of it, I would change
import qualified Data.ByteString as BS (readFile)
for
import qualified Data.ByteString.Lazy as BS (readFile)
as it seems sha1 needs a lazy bytestring
On Thu, Jan 29, 2009 at 13:25, emmanuel.delaborde <
[email protected]> wrote:
> Hello
>
> I have the following snippet :
>
> ----------------------------------------------------------
>
> module Main where
>
> import System.Environment (getArgs)
> import Data.Digest.OpenSSL.MD5 (md5sum)
> import Data.Digest.Pure.SHA (sha1, showDigest)
> import qualified Data.ByteString as BS (readFile)
>
> -- sha1 :: ByteString -> Digest
> -- readFile :: FilePath -> IO ByteString
> -- md5sum :: ByteString -> String
> -- showDigest :: Digest -> String
>
> checkHash :: String -> String -> String -> IO ()
> checkHash codec hash file =
> let f = case codec of
> --"md5" -> md5sum
> "sha1" -> showDigest . sha1
> _ -> error "Codec must be md5 or sha1 !" in
> BS.readFile file >>= \fileBS ->
> let fileHash = f fileBS in
> print (hash == fileHash)
>
> main =
> getArgs >>= \as ->
> case as of
> (codec:hash:file:_) -> checkHash codec hash file
> _ -> usage
>
> usage = print "checksum codec hash file"
>
> ----------------------------------------------------------
>
> which fails to compile, this is the error I get :
>
>
> checksum.hs:20:19:
> Couldn't match expected type `Data.ByteString.Lazy.Internal.ByteString'
> against inferred type `Data.ByteString.Internal.ByteString'
> In the first argument of `f', namely `fileBS'
> In the expression: f fileBS
> In the definition of `fileHash': fileHash = f fileBS
>
>
>
>
> it looks like (showDigest . sha1) expects
> Data.ByteString.Lazy.Internal.ByteString but gets
> Data.ByteString.Internal.ByteString
>
> What can I do ?
>
> Thanks
>
> E.
>
>
>
>
>
>
>
>
> -----------------------------------------------------------------------------------------------
>
> This e-mail (and any attachments) is confidential and may containpersonal
> views which are not the views of Cimex Media Ltd andany affiliated
> companies, unless specifically stated. It is intendedfor the use of the
> individual or group to whom it is addressed. Ifyou have received it in
> error, please delete it from your system,do not use, copy or disclose the
> information in any way nor act inreliance on it and please notify
> [email protected]
>
> A company registered in England Wales. Company Number 03765711
> Registered Office : The Olde Bakehouse, 156 Watling Street East, Towcester,
> Northants NN12 6DB
>
> This email was scanned by Postini, the leading provider in Managed Email
> Security.
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
--
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20090129/2bcbe134/attachment.htm
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 7, Issue 25
****************************************