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:  Get responsecode(Int) from simpleHTTP's      Response
      (Michael Orlitzky)
   2. Re:  Get responsecode(Int) from simpleHTTP's      Response
      (Jacques du Rand)


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

Message: 1
Date: Wed, 17 Oct 2012 07:52:47 -0400
From: Michael Orlitzky <[email protected]>
Subject: Re: [Haskell-beginners] Get responsecode(Int) from
        simpleHTTP's    Response
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

On 10/17/2012 02:51 AM, Jacques du Rand wrote:
> This is great works perfectly !
> I'm so new at haskell its scary !
> 
> One last question i dont *understand* one line ( just the right side )
> 
>        let (x,y,z) = rspCode response
> 
> 1) If i look at the documentation: Sorry for HTML. I see the
> constructors of Response and below it rspCode,rspReason,rspHeaders etc
> Are those parters or functions ?

They're functions that you can think of as the names of attributes of a
Response object (if you're coming from object-oriented programming).
There's a little magic going on under the hood, so you might want to
check out e.g.,

  http://learnyouahaskell.com/making-our-own-types-and-typeclasses

In particular the "Record Syntax" section. Papering over the details, in
an OO language, you might do something like,

  response.rspCode

to get the code out of a Response object. In Haskell, we just use a
function to do it. So,

  rspCode response

calls the rspCode function on 'response'. If you check the API docs,
  >
http://hackage.haskell.org/packages/archive/HTTP/4000.0.7/doc/html/Network-HTTP-Base.html#t:Response

you should see that rspCode takes a Response object and returns a
ResponseCode. But ResponseCode is just a synonym for (Int,Int,Int):

  type ResponseCode = (Int, Int, Int)

Therefore, rspCode takes a Response, and gives you back three Ints in an
ordered triplet.


> 2) I see the new version has a getResponseCode functions like
> getResponseBody with the signature:
> getResponseCode :: Result (Response a) -> IO ResponseCode
> getResponseCode (Left err) = fail (show err)
> getResponseCode (Right r)  = return (rspCode r)
> 
> What does this mean in the signature  *Result (Response a)* 

The Result type is really just a wrapper around Either. Either usually
takes two parameters, but Result fixes one of them to be ConnError:

  type Result a = Either ConnError a

So Result still takes one parameter. The parameter in this case is
(Response a).

For a more concrete example, think of a data type where you've got a box
and you can put stuff in it.

  data Box a = Box a

The 'a' parameter means that we can put different types of stuff in the
box. For example,

  foo :: Box Int
  foo = Box 3

  bar :: Box String
  bar = Box "Hello"

If this makes sense to you, then (Result (Response a)) is doing exactly
the same thing as (Box Int) or (Box String), only with slightly more
complicated types.



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

Message: 2
Date: Thu, 18 Oct 2012 08:18:09 +0200
From: Jacques du Rand <[email protected]>
Subject: Re: [Haskell-beginners] Get responsecode(Int) from
        simpleHTTP's    Response
To: Michael Orlitzky <[email protected]>
Cc: [email protected]
Message-ID:
        <CA+-VnXDFu8_APda3bV-Y3d-8=jr-kqh4w5fqnqmv9zbww-j...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Michael
That's a fantastic explanation !
I appreciate the time taken  and depth of it !

Best Regards
Jacques




On Wed, Oct 17, 2012 at 1:52 PM, Michael Orlitzky <[email protected]>wrote:

> On 10/17/2012 02:51 AM, Jacques du Rand wrote:
> > This is great works perfectly !
> > I'm so new at haskell its scary !
> >
> > One last question i dont *understand* one line ( just the right side )
> >
> >        let (x,y,z) = rspCode response
> >
> > 1) If i look at the documentation: Sorry for HTML. I see the
> > constructors of Response and below it rspCode,rspReason,rspHeaders etc
> > Are those parters or functions ?
>
> They're functions that you can think of as the names of attributes of a
> Response object (if you're coming from object-oriented programming).
> There's a little magic going on under the hood, so you might want to
> check out e.g.,
>
>   http://learnyouahaskell.com/making-our-own-types-and-typeclasses
>
> In particular the "Record Syntax" section. Papering over the details, in
> an OO language, you might do something like,
>
>   response.rspCode
>
> to get the code out of a Response object. In Haskell, we just use a
> function to do it. So,
>
>   rspCode response
>
> calls the rspCode function on 'response'. If you check the API docs,
>   >
>
> http://hackage.haskell.org/packages/archive/HTTP/4000.0.7/doc/html/Network-HTTP-Base.html#t:Response
>
> you should see that rspCode takes a Response object and returns a
> ResponseCode. But ResponseCode is just a synonym for (Int,Int,Int):
>
>   type ResponseCode = (Int, Int, Int)
>
> Therefore, rspCode takes a Response, and gives you back three Ints in an
> ordered triplet.
>
>
> > 2) I see the new version has a getResponseCode functions like
> > getResponseBody with the signature:
> > getResponseCode :: Result (Response a) -> IO ResponseCode
> > getResponseCode (Left err) = fail (show err)
> > getResponseCode (Right r)  = return (rspCode r)
> >
> > What does this mean in the signature  *Result (Response a)*
>
> The Result type is really just a wrapper around Either. Either usually
> takes two parameters, but Result fixes one of them to be ConnError:
>
>   type Result a = Either ConnError a
>
> So Result still takes one parameter. The parameter in this case is
> (Response a).
>
> For a more concrete example, think of a data type where you've got a box
> and you can put stuff in it.
>
>   data Box a = Box a
>
> The 'a' parameter means that we can put different types of stuff in the
> box. For example,
>
>   foo :: Box Int
>   foo = Box 3
>
>   bar :: Box String
>   bar = Box "Hello"
>
> If this makes sense to you, then (Result (Response a)) is doing exactly
> the same thing as (Box Int) or (Box String), only with slightly more
> complicated types.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20121018/917ac86a/attachment-0001.htm>

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

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


End of Beginners Digest, Vol 52, Issue 23
*****************************************

Reply via email to