Send Beginners mailing list submissions to
        beginners@haskell.org

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
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Function result being inversed (Daniel Fischer)
   2. Re:  Function result being inversed (aditya siram)
   3. Re:  Function result being inversed (Xavier Shay)
   4. Re:  Function result being inversed (Daniel Fischer)
   5.  Please help with some HXT code (Jeff Lasslett)
   6.  Bytestring question (Peter Braun)
   7.  Wildcards in expressions (Tom Murphy)
   8. Re:  Wildcards in expressions (Dean Herington)
   9. Re:  Looking for some guidance to installing      GHCI on MAC
      (Paul Higham)


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

Message: 1
Date: Tue, 25 Jan 2011 21:07:02 +0100
From: Daniel Fischer <daniel.is.fisc...@googlemail.com>
Subject: Re: [Haskell-beginners] Function result being inversed
To: beginners@haskell.org
Message-ID: <201101252107.03796.daniel.is.fisc...@googlemail.com>
Content-Type: text/plain;  charset="iso-8859-1"

On Tuesday 25 January 2011 21:00:11, Xavier Shay wrote:
> Hello,
> I am confused by the following code.
> I would expect results of True, False.
>
> $ ghci
> *Main> let f x = x 4
> *Main> f(<) 3
> False
> *Main> f(<) 5
> True

It's because

f (<) k = (f (<)) k = ((<) 4) k = (<) 4 k = 4 < k

or, shorter,

(<) 4 = (4 <)

>
> This came about because I was trying to refactor a sort function I
> wrote:
>
>    mySort [] = []
>    mySort (h:t) =
>      (f (<= h)) ++ [h] ++ (f (> h))
>      where f x = mySort (filter x t)
>
> I came up with this, which appears to work, though the comparison
> operators are backwards.
>
>    mySort [] = []
>    mySort (h:t) =
>      f(>) ++ [h] ++ f(<=)
>      where f x = mySort (filter (x h) t)

A right operator section,

(<*> x)

translates to

flip (<*>) x

in prefix notation.

>
> Cheers,
> Xavier



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

Message: 2
Date: Tue, 25 Jan 2011 14:09:39 -0600
From: aditya siram <aditya.si...@gmail.com>
Subject: Re: [Haskell-beginners] Function result being inversed
To: Xavier Shay <xavier-l...@rhnh.net>
Cc: beginners@haskell.org
Message-ID:
        <aanlktinfkrrfv49vyvf0rj25+f-rbzpfc1hbslzyc...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

You want something like:
  f x = x 4
  main = do
      print $ f $ (<) 3
      print $ f $ (<) 5

=> True
     False

(< 3) 4 translates to (4 < 3)
-deech
On Tue, Jan 25, 2011 at 2:00 PM, Xavier Shay <xavier-l...@rhnh.net> wrote:
> Hello,
> I am confused by the following code.
> I would expect results of True, False.
>
> $ ghci
> *Main> let f x = x 4
> *Main> f(<) 3
> False
> *Main> f(<) 5
> True
>
> This came about because I was trying to refactor a sort function I wrote:
>
> ?mySort [] = []
> ?mySort (h:t) =
> ? ?(f (<= h)) ++ [h] ++ (f (> h))
> ? ?where f x = mySort (filter x t)
>
> I came up with this, which appears to work, though the comparison operators
> are backwards.
>
> ?mySort [] = []
> ?mySort (h:t) =
> ? ?f(>) ++ [h] ++ f(<=)
> ? ?where f x = mySort (filter (x h) t)
>
> Cheers,
> Xavier
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>



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

Message: 3
Date: Wed, 26 Jan 2011 07:15:04 +1100
From: Xavier Shay <xavier-l...@rhnh.net>
Subject: Re: [Haskell-beginners] Function result being inversed
To: beginners@haskell.org
Message-ID: <4d3f2f48.8080...@rhnh.net>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Thanks to all responses. Makes sense now. For the record I have ended up 
with this:

   mySort [] = []
   mySort (h:t) =
     f(<=) ++ [h] ++ f(>)
     where f x = mySort (filter (not . x h) t)

I have a feeling I may be able to make the following work with some sort 
of type declaration but I haven't really learned much about them yet so 
I will revisit later. (At the moment it does not compile.)

   mySort [] = []
   mySort (h:t) =
     f(<=) ++ [h] ++ f(>)
     where f x = mySort (filter (h x) t)

Cheers,
Xavier

On 26/01/11 7:00 AM, Xavier Shay wrote:
> Hello,
> I am confused by the following code.
> I would expect results of True, False.
>
> $ ghci
> *Main> let f x = x 4
> *Main> f(<) 3
> False
> *Main> f(<) 5
> True
>
> This came about because I was trying to refactor a sort function I wrote:
>
> mySort [] = []
> mySort (h:t) =
> (f (<= h)) ++ [h] ++ (f (> h))
> where f x = mySort (filter x t)
>
> I came up with this, which appears to work, though the comparison
> operators are backwards.
>
> mySort [] = []
> mySort (h:t) =
> f(>) ++ [h] ++ f(<=)
> where f x = mySort (filter (x h) t)
>
> Cheers,
> Xavier
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners



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

Message: 4
Date: Tue, 25 Jan 2011 21:21:22 +0100
From: Daniel Fischer <daniel.is.fisc...@googlemail.com>
Subject: Re: [Haskell-beginners] Function result being inversed
To: beginners@haskell.org
Message-ID: <201101252121.22645.daniel.is.fisc...@googlemail.com>
Content-Type: text/plain;  charset="iso-8859-1"

On Tuesday 25 January 2011 21:15:04, Xavier Shay wrote:
> Thanks to all responses. Makes sense now. For the record I have ended up
> with this:
>
>    mySort [] = []
>    mySort (h:t) =
>      f(<=) ++ [h] ++ f(>)
>      where f x = mySort (filter (not . x h) t)
>
> I have a feeling I may be able to make the following work with some sort
> of type declaration but I haven't really learned much about them yet so
> I will revisit later. (At the moment it does not compile.)
>
>    mySort [] = []
>    mySort (h:t) =
>      f(<=) ++ [h] ++ f(>)
>      where f x = mySort (filter (h x) t)

Well, h is not a function, so (h x) isn't well formed.
You want a left operator section there, so you have to make the function x 
infix:

    where f x = mySort (filter (h `x`) t)

Backticks turn ordinary prefix functions into infix functions,

a `mod` b === mod a b

>
> Cheers,
> Xavier



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

Message: 5
Date: Wed, 26 Jan 2011 11:27:36 +1100
From: Jeff Lasslett <jeff.lassl...@gmail.com>
Subject: [Haskell-beginners] Please help with some HXT code
To: Beginners@haskell.org
Message-ID:
        <aanlktinbwurerrfmpjh1qvbcqq3amogftrnztwq1b...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Hello,

I am attempting to use HXT to scraped some html from the web.  In my
html are a few <div>s, all with a particular attribute.
I wish the get the text nodes out of these <div>s.

For each <div> I can use
    listA ( deep isText >>> getText ) >>> arr concat

to get all the text children an dmake one string out of them.

I'm just struggling to get all the text out of many similar <div>s.

Here's an html fragment similar to what I'm trying to process:

<tr>
  <td>
  <div attr="value">
    the quick
    <br/>
    brown fox
  </div>
  </td>
  <td>
     <div attr="value">
       jumps over<br/>
     </div>
   </td>
 </tr>
 <tr>
   <td>
     <div attr="value">
     the lazy dog
     </div>
   </td>
 </tr>

>From that lot I would like the string "the quick brown fox jumps over
the lazy dog".

How might this be achieved???

Thanks,
Jeff



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

Message: 6
Date: Wed, 26 Jan 2011 01:52:33 +0100
From: Peter Braun <peter-br...@gmx.net>
Subject: [Haskell-beginners] Bytestring question
To: beginners@haskell.org
Message-ID: <4d3f7051.70...@gmx.net>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hi everyone,

as an exercise for learning Haskell i'm writing a program that converts 
Ascii Stl files (a simple format for 3D model data) into binary Stl 
format. In my first attempt i used normal strings and the result was 
therefore very slow. Now i rewrote the program to use lazy bytestrings 
instead.

But well... it got even slower, so i'm probably doing something terribly 
wrong ;)

Here's what i do (the relevant parts):

...
asciiFile <- L.readFile (args!!0)
binHandle <- openBinaryFile (args!!1) WriteMode
let asciiLines = L.split (c2w '\n') asciiFile
...
parseFile binHandle (Normal, tail asciiLines) -- First line contains a 
comment
...

where L is Data.ByteString.Lazy. readFile ought to be lazy so it should 
not read the whole file into ram at this point. But when i split the 
lines and pass them to a function, is this still carried out lazily?

parseFile processes a line, depending on the StlLineType and then calls 
itself recursive like this:

parseFile :: Handle -> (StlLineType, [L.ByteString]) -> IO ()
...
parseFile h (Vertex1, s) = do
     let vals = extractVertex (head s)
     L.hPutStr h $ runPut (writeFloatArray vals)
     parseFile h (Vertex2, tail s)
...

extractVertex looks like this:

extractVertex :: L.ByteString -> [Float]
extractVertex s = let fracs = filter (\n -> L.length n > 0) $ L.split 
(c2w ' ') s
                                     in    [read (C.unpack(fracs!!1)) :: 
Float,
                                             read (C.unpack(fracs!!2)) 
:: Float,
                                             read (C.unpack(fracs!!3)) 
:: Float]

where C is Data.ByteString.Lazy.Char8. It splits a byte string, filters 
out the whitespaces and converts certain entries to floats. Maybe unpack 
is an expensive operation. Is there a better way to convert a Bytestring 
to float?

I know, this is bad Haskell code ;) But where is my grand, obvious 
misuse of Bytestring?

I'm grateful for any suggestion to improve that code. I'm using ghc, 
version 6.12.1.

Thank you,
Peter



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

Message: 7
Date: Tue, 25 Jan 2011 21:34:37 -0500
From: Tom Murphy <amin...@gmail.com>
Subject: [Haskell-beginners] Wildcards in expressions
To: beginners@haskell.org
Message-ID:
        <AANLkTi=7g_H9XDPfr=hzuav+tlsqxyhv4x-tkfdyl...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Hi everyone,
     Any suggestions?


Given that

          someList :: [(a,b,String)]

, the expression

          (_, _, "Tom") `elem` someList

seems so intuitive that, even though it doesn't work, I've been searching
for several hours for something similar.


     Do any of you know a way I can pull this off? I know there are plenty
of ways to get the functionality, but something similarly intuitive and
succinct would be great.

Thanks for the help,
Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110125/6e7c87a4/attachment-0001.htm>

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

Message: 8
Date: Tue, 25 Jan 2011 23:43:27 -0500
From: Dean Herington <heringtonla...@mindspring.com>
Subject: Re: [Haskell-beginners] Wildcards in expressions
To: Tom Murphy <amin...@gmail.com>, beginners@haskell.org
Message-ID: <a06240802c965563d4513@[10.0.1.6]>
Content-Type: text/plain; charset="us-ascii" ; format="flowed"

At 9:34 PM -0500 1/25/11, Tom Murphy wrote:
>Hi everyone,
>      Any suggestions?
>
>
>Given that
>
>           someList :: [(a,b,String)]
>
>, the expression
>
>           (_, _, "Tom") `elem` someList
>
>seems so intuitive that, even though it doesn't work, I've been 
>searching for several hours for something similar.
>
>
>      Do any of you know a way I can pull this off? I know there are 
>plenty of ways to get the functionality, but something similarly 
>intuitive and succinct would be great.
>
>Thanks for the help,
>Tom

Wildcards (the underscores) can appear only in patterns.  You could 
use a list comprehension, something like:

     (not . null) [ () | (_, _, "Tom") <- someList ]

Dean



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

Message: 9
Date: Tue, 25 Jan 2011 22:12:23 -0800
From: Paul Higham <polyg...@mac.com>
Subject: Re: [Haskell-beginners] Looking for some guidance to
        installing      GHCI on MAC
To: patricklynch <kmandpjly...@verizon.net>
Cc: beginners@haskell.org
Message-ID: <f82093f0-f7a5-41f7-ab0c-3b2d9898c...@mac.com>
Content-Type: text/plain; charset="windows-1252"; Format="flowed";
        DelSp="yes"

When you get the Apple account stuff sorted out and you are about to  
install X Code, make sure that you install the Unix Developers tools  
or you will get frustrated again with trying to install GHC.  Also,  
which Mac are you using?  If it's Intel based you should be ok, but if  
it's a PowerPC be careful which version of GHC you try to install - it  
doesn't seem to work with the later versions.

::paul

On Jan 24, 2011, at 9:29 AM, patricklynch wrote:

> Good morning,
>
> No luck?I tried to get a new password but I?ve been waiting for over  
> an hour and no response from Apple?
> I think the problem is that the ampersand ?@? in my Apple name is  
> invalid [according to their site and therefore they can not give me  
> a password]?
> ?looks like I?ll have to go to my Apple store and get some help or  
> an installation disk for Xcode?
>
> I have the PC up and running, so I?ll work with it in the mean time?
>
> I thought Macs were supposed to be easy to use?
>
> Thanks again?
>
> -----Original Message-----
> From: beginners-boun...@haskell.org [mailto:beginners-boun...@haskell.org 
> ] On Behalf Of JETkoten
> Sent: Monday, January 24, 2011 10:26 AM
> To: beginners@haskell.org
> Subject: Re: [Haskell-beginners] Looking for some guidance to  
> installing GHCI on MAC
>
> You're welcome. While you wait for Apple, why not try one more time?
>
> Go to this page:
>
> http://developer.apple.com/devcenter/download.action?path=/ios/ios_sdk_4.2__final/xcode_3.2.5_and_ios_sdk_4.2_final.dmg
>
> It will ask you for your Apple ID and password, put in
> kmandpjly...@verizon.net
> for user and add your password.
>
> If your login is not working, that might be why you get the invalid  
> message? If so, click the blue Forgot Password? link and it will  
> reset your password for you and email you to let you make a new one  
> so that you can then log in and get the file I linked above.
>
> After you log in, it should pop up a window and ask to Save or  
> Cancel. Choose Save, wait for the download to finish, open the .dmg  
> by double clicking and the rest should work.
>
> You don't need the Apple ID for installing Xcode just your OSX  
> system password...
>
> I'm not sure exactly what part of the install isn't working with  
> your Xcode install, but I think you're pretty close to getting it  
> working.
>
> On 1/24/11 9:35 AM, patricklynch wrote:
> Thanks for the 'heads up'.
>
> I got a 'free' Apple ID but it didn't work with the Apple download of
> Xcode...the Apple ID that I received from them was
> 'kmandpjly...@verizon.net' which is my email address...this gives the
> invalid message...
>
> I've notified Apple of this and am awaiting an answer from them...
>
> Good day
>
> -----Original Message-----
> From: beginners-boun...@haskell.org [mailto:beginners-boun...@haskell.org 
> ]
> On Behalf Of JETkoten
> Sent: Monday, January 24, 2011 5:37 AM
> To: beginners@haskell.org
> Subject: Re: [Haskell-beginners] Looking for some guidance to  
> installing
> GHCI on MAC
>
> Xcode is needed on the Mac to install *anything* that's not already a
> ready made (pre-compiled binary) program. Once you've got Xcode
> installed, it really does get easier!
>
> It is different than the PC because the Mac is using Xcode to convert
> the GHC and other Haskell platform files from the source code that
> people can read to a complied binary program that the computer can  
> read
> and that can run on your Mac. On the PC what you downloaded and
> installed was already compiled before you downloaded it.
>
> Once you get your free developer.apple.com account you then look for  
> the
> link for Xcode and pick the one for your version of OSX (10.4 or  
> 10.5 or
> 10.6).
>
> Download the file and when it finishes you can just double click it on
> the download window and it'll run the installer, or at least take  
> you to
> the downloaded installer in whatever folder it is in so you can then
> double click installer file and make it run. I forget which way it  
> works
> right now, but one of those will work.
>
> It'll then have you agree to the software license, and ask for your
> system password.
>
> Write it in, then wait a while for it to finish. It'll tell you when
> it's done... and after that you can try to install the Haskell  
> platform
> again and it should work.
>
> This is the beginner list: "Here, there is no such thing as a 'stupid
> question.'" Any other problems with your install? Post them back to  
> the
> list. You don't have to give up on it... keep at it and people here  
> will
> help you through.
>
> On 1/23/11 5:20 PM, patricklynch wrote:
>> ...i tried the March 2010 installation on the MAC and I get the same
>> result...if there is a requirement for Xcode, shouldn't it be  
>> listed in
> the
>> Installation Instructions... I tried another installation but it too
>> required Xcode...
>>
>> ...again, I was able to install GHC on a PC and was able to install  
>> HUGs
> on
>> the Mac...
>>
>> ...really frustrating... I'm not going to pay Apple $99, so I may  
>> have to
>> give up on the Mac for a while - bummer...
>>
>> -----Original Message-----
>> From: patricklynch [mailto:kmandpjly...@verizon.net]
>> Sent: Sunday, January 23, 2011 4:44 PM
>> To: 'Antoine Latter'
>> Cc: 'Wes Morgan'; 'beginners@haskell.org'
>> Subject: RE: [Haskell-beginners] Looking for some guidance to  
>> installing
>> GHCI on MAC
>>
>> ...sorry for being a 'klutz' - but I'm new to the mac too...
>> ...i'm guessing that I have Xcode installed...i see an X icon that  
>> has an
>> X11 label - when I click it, it displays nothing...bummer...
>> ...since I was able to install Hugs I'm guessing that Xcode is
>> installed...however, I have no way of knowing if this is true...and  
>> Apple
>> wants $99 for a Developer fee, bummer...I was not given an  
>> installation
>> disk...
>>
>> I went to the site: haskage.haskell.org\platform\mac.html...
>> It gives me a three step installation procedure...
>> ...the  1st deletes any previous installation of GHC - this worked...
>> ...the  2nd gets me to a screen that states Standard install on  
>> "Macintosh
>> HD"; with a message: click Install...{however, the Install Button  
>> can not
> be
>> clicked}...this is as far as I can get...
>>
>> -----Original Message-----
>> From: Antoine Latter [mailto:aslat...@gmail.com]
>> Sent: Sunday, January 23, 2011 2:55 PM
>> To: patricklynch
>> Cc: Wes Morgan; beginners@haskell.org
>> Subject: Re: [Haskell-beginners] Looking for some guidance to  
>> installing
>> GHCI on MAC
>>
>> The problem I had at first with the Haskell Platform installer was
>> that I didn't have Xcode installed.
>>
>> This should be on one of the OS X install discs, I think. You can  
>> also
>> download it from Apple:
>>
>> http://developer.apple.com/technologies/xcode.html
>>
>> It might be easier if you could send us the error message you're  
>> getting.
>>
>> Antoine
>>
>> On Sun, Jan 23, 2011 at 2:18 PM, patricklynch<kmandpjly...@verizon.net 
>> >
>> wrote:
>>> ...i tried to use the installation for Mac at Haskell.org, but it  
>>> gives
> me
>>> an error message [something like: call your software vendor]...
>>>
>>> ...i tried the Homebrew, see email below,  but it wants my Apple
> Developer
>>> id...i don't have one...
>>>
>>> ...i installed it on my pc and all it took was a single keystroke...
>>> ...i installed Hugs on my Mac without any problem..
>>>
>>> ...i'd appreciate any help, I really need to work with ghc on my mac
>>>
>>> Go Jets
>>>
>>> -----Original Message-----
>>> From: beginners-boun...@haskell.org
> [mailto:beginners-boun...@haskell.org]
>>> On Behalf Of Wes Morgan
>>> Sent: Sunday, January 23, 2011 7:36 AM
>>> To: beginners@haskell.org
>>> Subject: Re: [Haskell-beginners] Looking for some guidance to  
>>> installing
>>> GHCI on MAC
>>>
>>> I just used Homebrew (http://mxcl.github.com/homebrew/). Once that's
>>> installed, 'brew install ghc' gets you GHC, GHCi, cabal, etc.
>>>
>>> Wes
>>>
>>> On Jan 23, 2011, at 6:00 AM, "beginners-requ...@haskell.org"
>>> <beginners-requ...@haskell.org>  wrote:
>>>
>>>> Re: [Haskell-beginners] Looking for some guidance to
>>>>     installing GHCI on MAC
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners@haskell.org
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners@haskell.org
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners@haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110125/1e1c4307/attachment.htm>

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

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 31, Issue 32
*****************************************

Reply via email to