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:  do-notation question (Ertugrul Soeylemez)
   2.  Multiple versions (Tom Murphy)
   3.  hidden package error when using Snap (Todd Porter)
   4. Re:  Multiple versions (Mark Bestley)
   5.  More direct binding of IO result (Christopher Howard)
   6. Re:  More direct binding of IO result (Michael Snoyman)
   7. Re:  More direct binding of IO result (Arlen Cuss)
   8. Re:  More direct binding of IO result (Michael Snoyman)
   9. Re:  More direct binding of IO result (Arlen Cuss)


----------------------------------------------------------------------

Message: 1
Date: Sat, 14 May 2011 18:41:36 +0200
From: Ertugrul Soeylemez <[email protected]>
Subject: Re: [Haskell-beginners] do-notation question
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII

[email protected] wrote:

>  In The Yesod Book, I see the following code:
>
>  defaultLayout contents = do
>          PageContent title headTags bodyTags <- widgetToPageContent $ do
>              addCassius ...
>
>  How does this work?  Is bodyTags drawn from widgetToPageContent and
>  then used as the third argument to PageContent?

This is just a regular pattern match, just like any of these:

  x         <- someComp
  (x, y)    <- someTupleComp
  Just x    <- someMaybeComp
  [x, y, z] <- someListComp
  x : y : _ <- someListComp
  PageContent title headTags bodyTags <- somePageContentComp

or:

  someFunc (PageContent title headTags bodyTags) = ...
  someFunc (Just x) = ...

What may confuse you is that PageContent is used in prefix notation
without any parentheses, whereas the usual constructors used in pattern
matching are written in infix or special syntax notation.


Greets,
Ertugrul


-- 
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/





------------------------------

Message: 2
Date: Sat, 14 May 2011 22:22:03 -0400
From: Tom Murphy <[email protected]>
Subject: [Haskell-beginners] Multiple versions
To: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hi all,
Despite my best efforts, there are multiple versions of the Haskell
Platform on my system.

I'm running Mac OSX, 10.6. I've installed the newest Haskell Platform,
from its installer package.


In /Library/Frameworks/GHC.framework/Versions, there is only one
folder: the latest.
Previously, though, I had to delete by hand an older version of GHC in
the Versions folder.

There are no Haskell or GHC folders in ~/Library.

When I run the ghci that's in the
/Library/Frameworks/GHC.framework/Versions folder, it's the right
version. Yet when I type "ghci" in the prompt, it gives me "GHCi,
version 6.10.4"


Any help would be very appreciated!
Tom



------------------------------

Message: 3
Date: Sun, 15 May 2011 15:24:12 +1000
From: Todd Porter <[email protected]>
Subject: [Haskell-beginners] hidden package error when using Snap
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

Hi,

I am using the parseTime function from Data.Time.Format. The first parameter is 
a TimeLocale defined in System.Locale (old-locale-1.0.0.2).

I first wrote a trivial little module to test my understanding in ghci:

module Tbasic where

import Data.Time
import System.Locale

parseDate :: String -> Maybe UTCTime
parseDate s = parseTime defaultTimeLocale "%d/%m/%Y" s

Works fine.

I then tried using this same function in my Snap web application. The 
application builds (via cabal install) fine. However when I start up the 
application and make my first request I get the following error:

A web handler threw an exception. Details:
Compile errors:

Could not find module `System.Locale':
  It is a member of the hidden package `old-locale-1.0.0.2'.
  Use -v to see a list of the files searched for.

I have added old-locale to Build-depends in the applications .cabal file.

old-locale-1.0.0.2 appears in the global list of packages when I run ghc-pkg 
list

Unsure what to try next. To be honest I don't understand a compile error at 
runtime given I didn't activate dynamic recompilation (i.e. I last built using 
cabal install, not cabal install -fdevelopment).

appreciate any advice, Todd


------------------------------

Message: 4
Date: Sun, 15 May 2011 05:56:37 +0100
From: news{@bestley.co.uk (Mark Bestley)
Subject: Re: [Haskell-beginners] Multiple versions
To: [email protected]
Message-ID: <1k1aofg.1pm8b9iubvwiwN%news{@bestley.co.uk>

Tom Murphy <[email protected]> wrote:

> Hi all,
> Despite my best efforts, there are multiple versions of the Haskell
> Platform on my system.
> 
> I'm running Mac OSX, 10.6. I've installed the newest Haskell Platform,
> from its installer package.
> 
> 
> In /Library/Frameworks/GHC.framework/Versions, there is only one
> folder: the latest.
> Previously, though, I had to delete by hand an older version of GHC in
> the Versions folder.
> 
> There are no Haskell or GHC folders in ~/Library.
> 
> When I run the ghci that's in the
> /Library/Frameworks/GHC.framework/Versions folder, it's the right
> version. Yet when I type "ghci" in the prompt, it gives me "GHCi,
> version 6.10.4"
> 
> 
> Any help would be very appreciated!
> Tom

What does 
which ghci
at the prompt show?

this is the actual binary - Haskell platform puts this in /usr/bin
(which is not good as this is reserved for Apple's code and so could be
deleted by a OS upgrade)


-- 
Mark




------------------------------

Message: 5
Date: Sat, 14 May 2011 22:27:02 -0800
From: Christopher Howard <[email protected]>
Subject: [Haskell-beginners] More direct binding of IO result
To: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

I understand that one can bind the unwrapped results of IO functions to
variables, and pass them to functions, like so:

main = do filecontents <- readFile "data.txt"
          putStrLn filecontents

But does the syntax allow you to cut out the middle man, so to speak,
and bind the results directly to the parameter? Like

-- Tried this and it didn't work.
main = do putStrLn (<- readFile "data.txt")

-- 
frigidcode.com
theologia.indicium.us



------------------------------

Message: 6
Date: Sun, 15 May 2011 09:29:10 +0300
From: Michael Snoyman <[email protected]>
Subject: Re: [Haskell-beginners] More direct binding of IO result
To: Christopher Howard <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

On Sun, May 15, 2011 at 9:27 AM, Christopher Howard <
[email protected]> wrote:

> I understand that one can bind the unwrapped results of IO functions to
> variables, and pass them to functions, like so:
>
> main = do filecontents <- readFile "data.txt"
>          putStrLn filecontents
>
> But does the syntax allow you to cut out the middle man, so to speak,
> and bind the results directly to the parameter? Like
>
> -- Tried this and it didn't work.
> main = do putStrLn (<- readFile "data.txt")
>
> do-notation is just syntactic sugar for the ">>" and ">>=" operators. Your
example gets translated internally to:

    readFile "data.txt" >>= \filecontents -> putStrLn filecontents

To get rid of that extra "filecontents", you could instead write:

    readFile "data.txt" >>= putStrLn

HTH,
Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110515/c3d5054f/attachment-0001.htm>

------------------------------

Message: 7
Date: Sun, 15 May 2011 16:49:46 +1000
From: Arlen Cuss <[email protected]>
Subject: Re: [Haskell-beginners] More direct binding of IO result
To: Christopher Howard <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID: <1305442186.2734.24.camel@asu>
Content-Type: text/plain; charset="utf-8"

> -- Tried this and it didn't work.
> main = do putStrLn (<- readFile "data.txt")
> 

My question; how come fmap doesn's also work here? (though it's not a
syntax-based solution):

Prelude> fmap putStrLn (readFile "data.txt")
Prelude>

I thought it may have operated to make a new IO action, but if that were
the case then ghci should have executed the result here.

A
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110515/4e401293/attachment-0001.pgp>

------------------------------

Message: 8
Date: Sun, 15 May 2011 09:55:06 +0300
From: Michael Snoyman <[email protected]>
Subject: Re: [Haskell-beginners] More direct binding of IO result
To: Arlen Cuss <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

On Sun, May 15, 2011 at 9:49 AM, Arlen Cuss <[email protected]> wrote:

> > -- Tried this and it didn't work.
> > main = do putStrLn (<- readFile "data.txt")
> >
>
> My question; how come fmap doesn's also work here? (though it's not a
> syntax-based solution):
>
> Prelude> fmap putStrLn (readFile "data.txt")
> Prelude>
>
> I thought it may have operated to make a new IO action, but if that were
> the case then ghci should have executed the result here.
>
>
Let's look at the types. Specializing to IO,

    readFile "data.txt" :: IO String

    fmap :: (a -> b) -> IO a -> IO b
    putStrLn :: String -> IO ()

    fmap putStrLn :: IO String -> IO (IO ())

Notice how there are now *two* IOs in "fmap putStrLn". Therefore, the result
of "fmap putStrLn (readFile "data.txt")" is of type "IO (IO ())".

The way to get rid of that extra IO is via the join function, which has type
(specialized for IO):

    join :: IO (IO a) -> IO a

So you could write:

    import Control.Monad (join)
    main = join (fmap putStrLn (readFile "data.txt"))

Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110515/a5e09824/attachment-0001.htm>

------------------------------

Message: 9
Date: Sun, 15 May 2011 17:10:42 +1000
From: Arlen Cuss <[email protected]>
Subject: Re: [Haskell-beginners] More direct binding of IO result
To: Michael Snoyman <[email protected]>
Cc: Haskell, Beginners <[email protected]>
Message-ID: <1305443442.2734.27.camel@asu>
Content-Type: text/plain; charset="utf-8"


>     fmap putStrLn :: IO String -> IO (IO ())

Ah, thanks! Should've thought more clearly about the types involved
here!

>     join :: IO (IO a) -> IO a

Super-handy to know :D I also note that `concat' is simply `join' in the
list monad!

> Michael

Arlen
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110515/5a97dbea/attachment.pgp>

------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 35, Issue 28
*****************************************

Reply via email to