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.  List Comprehensions (Hamster)
   2. Re:  List Comprehensions (Benjamin Edwards)
   3. Re:  List Comprehensions (Henk-Jan van Tuyl)
   4. Re:  Network.Curl POST body not showing up (Bryce Verdier)
   5.  Problem with Data.Map and IO... (Manfred Lotz)
   6. Re:  Problem with Data.Map and IO... (Michael Xavier)


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

Message: 1
Date: Wed, 11 May 2011 21:36:30 +1000
From: Hamster <[email protected]>
Subject: [Haskell-beginners] List Comprehensions
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hello,

I am trying to understand list comprehensions (I am very new to
Haskell) and there's one thing I simply don't understand.

If I have code that looks like:

combinations = [ (x,y) | x <-[1,2,3], y<-[1,2,3]]

Then it happily gives me all the possible combinations of x and y.
[(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3)]

However...

If I change the function to look like:

combinations xs ys = [ (x,y) | x <-[xs], y<-[ys]]

The output changes to:
[([1,2,3],[1,2,3])]

I don't understand what's going on there. Is there any way I can get
it to produce all the combinations of a user supplied list?

Thanks

H.



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

Message: 2
Date: Wed, 11 May 2011 12:42:54 +0100
From: Benjamin Edwards <[email protected]>
Subject: Re: [Haskell-beginners] List Comprehensions
To: Hamster <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

It needs to read x <- xs

You are wrapping a list in a list constructor :-)

On 11 May 2011 12:37, "Hamster" <[email protected]> wrote:

Hello,

I am trying to understand list comprehensions (I am very new to
Haskell) and there's one thing I simply don't understand.

If I have code that looks like:

combinations = [ (x,y) | x <-[1,2,3], y<-[1,2,3]]

Then it happily gives me all the possible combinations of x and y.
[(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3)]

However...

If I change the function to look like:

combinations xs ys = [ (x,y) | x <-[xs], y<-[ys]]

The output changes to:
[([1,2,3],[1,2,3])]

I don't understand what's going on there. Is there any way I can get
it to produce all the combinations of a user supplied list?

Thanks

H.

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110511/544c6b62/attachment-0001.htm>

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

Message: 3
Date: Wed, 11 May 2011 13:46:34 +0200
From: "Henk-Jan van Tuyl" <[email protected]>
Subject: Re: [Haskell-beginners] List Comprehensions
To: [email protected], Hamster <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-15; format=flowed;
        delsp=yes

On Wed, 11 May 2011 13:36:30 +0200, Hamster <[email protected]> wrote:

> If I change the function to look like:
>
> combinations xs ys = [ (x,y) | x <-[xs], y<-[ys]]
>
> The output changes to:
> [([1,2,3],[1,2,3])]
>
> I don't understand what's going on there. Is there any way I can get
> it to produce all the combinations of a user supplied list?

Change the function to:
   combinations xs ys = [ (x,y) | x <- xs, y <- ys]

xs and ys are already lists; if you put square brackets around them, you  
get a list with another list as the only element.

Regards,
Henk-Jan van Tuyl


-- 
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
--



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

Message: 4
Date: Wed, 11 May 2011 09:49:29 -0700
From: Bryce Verdier <[email protected]>
Subject: Re: [Haskell-beginners] Network.Curl POST body not showing up
To: haskellbeginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"

I would be interested in this as well. I'm trying to use Network.Curl 
for a personal project, also using a method_post, and am not able to get 
a response. Though I know it's connecting.

I _think_ that I need to use CurlWriteFunction, but I'm still new to 
Haskell & not sure how to work with that option.

Bryce


On 05/10/2011 10:25 PM, Michael Xavier wrote:
> Hi all,
>
> I was hoping one of you was pretty proficient with Network.Curl to 
> help me out, as I am not. I need to post JSON to an HTTPS endpoint 
> using HTTP Basic Authentication. The endpoint will not accept the 
> request unless the content-type is set to application/json.
>
> If I were using the curl utility, I'd do something like
>
> curl -H "Content-Type: application/json" -d "{blah:42}" -u 
> 'myuser:mypass' https://example.com/api.json
>
> I'd really like to use curl's curlGetString because the return type is 
> perfect, the code and the body.
>
> I've tried curlGetString, curlPost and curlMultiPost and all 
> combinations of CurlOption, but I can either get it to send the 
> correct content type header with empty content or send the post body 
> with the content type defaulted to urlencoded or multipart/form-data. 
> My code right now looks something like:
>
> doPost :: (ToJSON a) => T.Text -> T.Text -> T.Text -> a -> CampfireM 
> (CurlCode, String)
> doPost key sub path pay = liftIO $ curlGetString (url path sub) opts
>                      where opts    = method_POST ++ curlOpts key ++ 
> [CurlVerbose True, post, ct]
>                            post    = CurlPostFields [T.unpack encPay]
>                            ct      = CurlHttpHeaders ["Content-Type: 
> application/json"]
>                            encPath = encodePath path encPay
>                            encPay  = encodePayload pay
>
> The post fields will not be in the form of "key=value", but rather a 
> JSCODE:
>
> * Server auth using Basic with user 'SECRET_KEY'
> > POST /rooms/287132/speak.json HTTP/1.1
> Authorization: Basic SECRET_KEY
> Host: example.com <http://example.com>
> Accept: */*
> Content-Type: application/json
> Content-Length: 103
>
> * The requested URL returned error: 500
> * Closing connection #0
> * HTTP response code said error
>
> It would seem to me from this output that no actual content was sent. 
> What am I doing wrong? I'd really like to use curlGetString instead of 
> some of the more complex curl functions.
>
> Thanks!
>
> -- 
> Michael Xavier
> http://www.michaelxavier.net
>
>
> -- 
> Michael Xavier
> http://www.michaelxavier.net
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110511/3b2aff0a/attachment-0001.htm>

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

Message: 5
Date: Wed, 11 May 2011 20:05:27 +0200
From: Manfred Lotz <[email protected]>
Subject: [Haskell-beginners] Problem with Data.Map and IO...
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII

Hi there,
I've got a problem creating a map. 

I have a list of dataset names and adding those dataset names into a
map works fine like this:

<----------------------------snip-------------------------------->
module Main where

import Data.List
import qualified Data.Map as M


insertRec :: M.Map String String -> String -> M.Map String String
insertRec m e =
  let f = M.lookup e m in
  if  f == Nothing
  then
     M.insert e  "bla" m
  else
     m
  
    
createMap :: [String] -> M.Map String String 
createMap lst =
  let m = M.empty in
  foldl' insertRec m  lst 

  
main :: IO ()
main = do
  let xmlfiles = [ "a.xml","f.xml"]
  let ht = createMap xmlfiles
  print ht
<----------------------------snap-------------------------------->


However, actually I want to parse the xml files and adding content into
the map. 

For this I have a function 
getXmlContent :: FilePath -> IO (String,String)

and would like to do something like this:

<----------------------------snip-------------------------------->
insertRec m e = do
  c <- getXmlContent e 
  let k = fst c
  let v = snd c
  M.insert  k v  m
<----------------------------snap-------------------------------->

Unfortunately, this doesn't work because of IO. I have no glue how to
get this done.  


Any help appreciated.



-- 
Thanks,
Manfred






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

Message: 6
Date: Wed, 11 May 2011 11:41:46 -0700
From: Michael Xavier <[email protected]>
Subject: Re: [Haskell-beginners] Problem with Data.Map and IO...
To: Manfred Lotz <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

I believe let when you're in do notation is for pure functions. Since c is
IO (String String), I think what you might try is:

c <- getXmlContent e
k <- fst c
v  <- snd c

Or even better, use pattern matching:

(k, v) <- getXmlContent e

Someone please step in if I'm misrepresenting how it's done.


On Wed, May 11, 2011 at 11:05 AM, Manfred Lotz <[email protected]>wrote:

> Hi there,
> I've got a problem creating a map.
>
> I have a list of dataset names and adding those dataset names into a
> map works fine like this:
>
> <----------------------------snip-------------------------------->
> module Main where
>
> import Data.List
> import qualified Data.Map as M
>
>
> insertRec :: M.Map String String -> String -> M.Map String String
> insertRec m e =
>  let f = M.lookup e m in
>  if  f == Nothing
>  then
>     M.insert e  "bla" m
>  else
>     m
>
>
> createMap :: [String] -> M.Map String String
> createMap lst =
>  let m = M.empty in
>  foldl' insertRec m  lst
>
>
> main :: IO ()
> main = do
>  let xmlfiles = [ "a.xml","f.xml"]
>  let ht = createMap xmlfiles
>  print ht
> <----------------------------snap-------------------------------->
>
>
> However, actually I want to parse the xml files and adding content into
> the map.
>
> For this I have a function
> getXmlContent :: FilePath -> IO (String,String)
>
> and would like to do something like this:
>
> <----------------------------snip-------------------------------->
> insertRec m e = do
>  c <- getXmlContent e
>  let k = fst c
>  let v = snd c
>  M.insert  k v  m
> <----------------------------snap-------------------------------->
>
> Unfortunately, this doesn't work because of IO. I have no glue how to
> get this done.
>
>
> Any help appreciated.
>
>
>
> --
> Thanks,
> Manfred
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



-- 
Michael Xavier
http://www.michaelxavier.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110511/89192a38/attachment.htm>

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

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


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

Reply via email to