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:  Re: Is this overkill? (Magnus Therning)
   2.  Fetching a URI (Adam Keys)
   3. Re:  Fetching a URI (aditya siram)
   4. Re:  Fetching a URI (Aleksandar Dimitrov)
   5.  accessor function scope (Michael Mossey)
   6.  combine pattern matching against named fields    and tuples
      (Michael Mossey)
   7. Re:  combine pattern matching against named fields        and tuples
      (Brandon S. Allbery KF8NH)
   8. Re:  combine pattern matching against named fields        and tuples
      (Thomas Davie)
   9. Re:  accessor function scope (Francesco Bochicchio)


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

Message: 1
Date: Sun, 05 Apr 2009 17:08:20 +0100
From: Magnus Therning <[email protected]>
Subject: Re: [Haskell-beginners] Re: Is this overkill?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

Chaddaï Fouché wrote:
> On Sat, Apr 4, 2009 at 5:20 AM, Zachary Turner <[email protected]> 
> wrote:
>>> With Conal's semantic editor combinators
>>>
>>>  http://conal.net/blog/posts/semantic-editor-combinators/
>>>
>>> it would be written as
>>>
>>>  trueIndices =
>>>    (result . result) (map fst . filter snd . zip [0..]) (zipWith (&&))
>>
>> That was a pretty interesting blog post, and easily understandable which is
>> always nice.  Thanks for the link.  I also had never even used the zipWith
>> function, so thanks for pointing out that equivalence.
> 
> I'm not sure you really want to write this pointfree... Generally I
> tend to avoid it when there's two arguments of identical standing.
> Also the (map fst . filter snd...) is a Data.List function
> (findIndices) :
> 
> trueIndices xs ys = findindices id $ zipWith (&&) xs ys
> 
> I love the pointfree style and it might be a good exercise to try and
> transcribe any function to pointfree, but sometimes pointful is just
> clearer.

Or to put it differently, sometimes "pointfree is pointless" ;-)

/M

-- 
Magnus Therning                        (OpenPGP: 0xAB4DFBA4)
magnus@therning.org          Jabber: magnus@therning.org
http://therning.org/magnus         identi.ca|twitter: magthe

Haskell is an even 'redder' pill than Lisp or Scheme.
     -- PaulPotts

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: OpenPGP digital signature
Url : 
http://www.haskell.org/pipermail/beginners/attachments/20090405/cdb91aa1/signature-0001.bin

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

Message: 2
Date: Sun, 5 Apr 2009 22:07:16 -0500
From: Adam Keys <[email protected]>
Subject: [Haskell-beginners] Fetching a URI
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes

I'm trying to write a wrapper for a REST service. However, I find  
myself stumped by the simplest part: merely performing a GET on a URI.

I'm using the HTTP Cabal package. It specifies an example like so:

> simpleHTTP (getRequest "http://www.haskell.org/";) >>= fmap (take  
> 100) . getResponseBody


However, it seems I'm either importing the library incorrectly or  
there is a discrepancy between the documentation and the library. I  
can't seem to call getRequest.

> :) ghc-pkg list
> ...
> /Users/adamkeys/.ghc/i386-darwin-6.8.2/package.conf:
>     Cabal-1.6.0.1, HTTP-3001.1.3, HTTP-4000.0.4, Shellac-0.9.5,
> ...
>
> GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
> Loading package base ... linking ... done.
> Prelude> import Network.HTTP
> Prelude Network.HTTP> :type getRequest
>
> <interactive>:1:0: Not in scope: `getRequest'

Am I missing something obvious here?

--
~akk



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

Message: 3
Date: Sun, 5 Apr 2009 22:46:04 -0500
From: aditya siram <[email protected]>
Subject: Re: [Haskell-beginners] Fetching a URI
To: Adam Keys <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

At first I got the same error but when I installed HTTP-4000.0.5 using Cabal
your code worked.

hth,
deech

On Sun, Apr 5, 2009 at 10:07 PM, Adam Keys <[email protected]> wrote:

> I'm trying to write a wrapper for a REST service. However, I find myself
> stumped by the simplest part: merely performing a GET on a URI.
>
> I'm using the HTTP Cabal package. It specifies an example like so:
>
>  simpleHTTP (getRequest "http://www.haskell.org/";) >>= fmap (take 100) .
>> getResponseBody
>>
>
>
> However, it seems I'm either importing the library incorrectly or there is
> a discrepancy between the documentation and the library. I can't seem to
> call getRequest.
>
>  :) ghc-pkg list
>> ...
>> /Users/adamkeys/.ghc/i386-darwin-6.8.2/package.conf:
>>    Cabal-1.6.0.1, HTTP-3001.1.3, HTTP-4000.0.4, Shellac-0.9.5,
>> ...
>>
>> GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
>> Loading package base ... linking ... done.
>> Prelude> import Network.HTTP
>> Prelude Network.HTTP> :type getRequest
>>
>> <interactive>:1:0: Not in scope: `getRequest'
>>
>
> Am I missing something obvious here?
>
> --
> ~akk
>
> _______________________________________________
> 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/20090405/be4f76a1/attachment-0001.htm

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

Message: 4
Date: Mon, 6 Apr 2009 14:37:47 +0200
From: Aleksandar Dimitrov <[email protected]>
Subject: Re: [Haskell-beginners] Fetching a URI
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

Hi Adam,

>> ghc-pkg list
>> ...
>> /Users/adamkeys/.ghc/i386-darwin-6.8.2/package.conf:
>>    Cabal-1.6.0.1, HTTP-3001.1.3, HTTP-4000.0.4, Shellac-0.9.5,
>> ...

It seems you have two versions of HTTP installed. I'm not really sure
about HTTP-3.x.x.x's API, but I'd wage a guess that it doesn't define
`getRequest`. When importing in ghci, your installation probably picks
the older one instead of the new version.

Try hiding the old package and see if it fixes your problem:

> ghc-pkg hide HTTP-3001.1.13

You can unhide it using `ghc-pkg unhide HTTP-3001.1.13`.

HTH,
Aleks


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

Message: 5
Date: Tue, 07 Apr 2009 00:01:12 -0700
From: Michael Mossey <[email protected]>
Subject: [Haskell-beginners] accessor function scope
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

I'm coming from the OO world and trying to adapt.

I've noticed that if I declare two types like this

data Thing1 = Thing1 { itemPos :: Int }
data Thing2 = Thing2 { itemPos :: Int }

then I get the error "Multiple declarations of Main.itemPos"

However, I can successfully do this:

type Pos = ( Int, Int )
type Dimension = ( Int, Int, Int, Int )
data LayoutItem = StaffItem { itemPos :: Pos,
                               itemDim :: Dimension }
                 | TextItem { itemPos :: Pos,
                              itemDim :: Dimension }


d1 = TextItem ...
d2 = StaffItem ...
i1 = itemPos d
i2 = itemPos d2

This seems to define itemPos in a way that can sense whether it's dealing with 
a 
StaffItem-type LayoutItem or a TextItem-type LayoutItem. I don't know if this 
would 
be considered an overloaded operator. However, it does resemble derived class 
in OO.

For that matter, I don't know what the term is for a "StaffItem-type 
LayoutItem". The 
type is clearly LayoutItem. "StaffItem" is the constructor. How do you refer to 
the 
concept of a LayoutItem constructed via a StaffItem?

Again, StaffItem and TextItem resemble derived classes in OO.

Any clarification welcome.
-Mike


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

Message: 6
Date: Tue, 07 Apr 2009 00:30:04 -0700
From: Michael Mossey <[email protected]>
Subject: [Haskell-beginners] combine pattern matching against named
        fields  and tuples
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

I'm trying to do something like this:

data Thing = Thing { field1, field2 :: ( Int, Int ) }

myfunc = Thing { field1 ( _, x ) } = x

but it doesn't work. That is, I want to match against the second item of the 
tuple 
which is the named field1. I'm not just trying to do this particular thing, but 
trying to figure out if some kind of general pattern matching can be done like 
this.



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

Message: 7
Date: Tue, 7 Apr 2009 03:37:02 -0400
From: "Brandon S. Allbery KF8NH" <[email protected]>
Subject: Re: [Haskell-beginners] combine pattern matching against
        named fields    and tuples
To: Michael Mossey <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

On 2009 Apr 7, at 3:30, Michael Mossey wrote:
> I'm trying to do something like this:
>
> data Thing = Thing { field1, field2 :: ( Int, Int ) }
>
> myfunc = Thing { field1 ( _, x ) } = x

 > myfunc (Thing {field1 = (_,x)}) = x
using record pattern matching

-- 
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [email protected]
system administrator [openafs,heimdal,too many hats] [email protected]
electrical and computer engineering, carnegie mellon university    KF8NH


-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url : 
http://www.haskell.org/pipermail/beginners/attachments/20090407/3bf147a7/PGP-0001.bin

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

Message: 8
Date: Tue, 7 Apr 2009 09:40:02 +0200
From: Thomas Davie <[email protected]>
Subject: Re: [Haskell-beginners] combine pattern matching against
        named fields    and tuples
To: Michael Mossey <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes


On 7 Apr 2009, at 09:30, Michael Mossey wrote:

> I'm trying to do something like this:
>
> data Thing = Thing { field1, field2 :: ( Int, Int ) }
>
> myfunc = Thing { field1 ( _, x ) } = x
>
> but it doesn't work. That is, I want to match against the second  
> item of the tuple which is the named field1. I'm not just trying to  
> do this particular thing, but trying to figure out if some kind of  
> general pattern matching can be done like this.

Firstly, you have an extra equals in there, secondly, in a pattern  
match constructions must go in parentheses, and finally, you're  
missing an equals inside the record:

myFunc (Think {field1 = (_,x)}) = x

Bob


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

Message: 9
Date: Tue, 7 Apr 2009 10:03:50 +0200
From: Francesco Bochicchio <[email protected]>
Subject: Re: [Haskell-beginners] accessor function scope
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

2009/4/7 Michael Mossey <[email protected]>

> I'm coming from the OO world and trying to adapt.
>

me too :-)


>
> For that matter, I don't know what the term is for a "StaffItem-type
> LayoutItem". The type is clearly LayoutItem. "StaffItem" is the constructor.
> How do you refer to the concept of a LayoutItem constructed via a StaffItem?
>
> Again, StaffItem and TextItem resemble derived classes in OO.
>

To me, they are more close to C union : a data type than can alternatively
have different structures,
In your example, LayoutItem is a type name, while StaffItem and TextItem are
constructor, that is functions.
Saying that a function specializes a type is a bit of a stretch, I think ...

Nevertheless, they can sometime be used to accomplish the same goal : where
in OO you define an abstact class and then
specialize with concrete classes to model a classification, in haskell you
can define a data type with alternate constructors.

I think that data types with alternate constructores are called algebraic
data types in haskellese, but I'm not sure of that ...


>
> Any clarification welcome.
> -Mike
>

Ciao
-----
FB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20090407/2bfbb60a/attachment.htm

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

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


End of Beginners Digest, Vol 10, Issue 6
****************************************

Reply via email to