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: A first try (David Place)
2. Do I understand this well (Roelof Wobben)
3. Re: Do I understand this well (Markus L?ll)
4. Re: A first try (David Place)
5. Re: Do I understand this well (Roelof Wobben)
6. Re: Do I understand this well (Lyndon Maydwell)
7. Re: A first try (Manfred Lotz)
8. Re: Doing IO in terms of Arrow (Ertugrul Soeylemez)
9. Re: A first try (Mike Meyer)
10. Re: Would you shed light on "undefined values" please?
(Ertugrul Soeylemez)
----------------------------------------------------------------------
Message: 1
Date: Mon, 27 Jun 2011 10:51:03 -0400
From: David Place <[email protected]>
Subject: Re: [Haskell-beginners] A first try
To: Manfred Lotz <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Jun 27, 2011, at 9:58 AM, Manfred Lotz wrote:
>> To ensure that the entire file is read, you can seq on the length,
>>
>> xml <- U.hGetContents inh
>> let content = parseXMLDoc xml
>> length xml `seq` case content of ...
>>
>
> Thanks a lot for the suggestion. Works fine.
>
> I only tried deepseq because my first try with seq
>
> let content = xml `seq` parseXMLDoc xml
>
> didn't work.
>
You can call me squeamish, but using a pure function (length) for its
side-effects seems kind of kludge-y. :-)
____________________
David Place
Owner, Panpipes Ho! LLC
http://panpipesho.com
[email protected]
------------------------------
Message: 2
Date: Mon, 27 Jun 2011 14:51:46 +0000
From: Roelof Wobben <[email protected]>
Subject: [Haskell-beginners] Do I understand this well
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hello,
Im stil reading chapter4
Now we have this : addVectors (x1, y1) (x2, y2) = (x1 + x2, y1 + y2)
do I understand it that the outcome of x1+x2 will be saved in the last
expression x1 + x2
But on which variable can the outcome be found.
Roelof
------------------------------
Message: 3
Date: Mon, 27 Jun 2011 18:18:43 +0300
From: Markus L?ll <[email protected]>
Subject: Re: [Haskell-beginners] Do I understand this well
To: Roelof Wobben <[email protected]>, [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
addVectors is a function definition, so it doesn't actually do
anything until you apply it.
In addThree you would use it like this
> addThree vec1 vec2 vec3 = let
> interm = addVectors vec1 vec2
> in addVectors interm vec3
or
> addThree vec1 vec2 vec3 = addVectors interm vec3
> where interm = addVectors vec1 vec2
or
> addThree vec1 vec2 vec3 = addVectors (addVectors vec1 vec2) vec3
or
> addThree vec1 vec2 vec3 = vec1 `addVectors` vec2 `addVectors` vec3
with the last one looking really nice.
In the first two I bind the result to an intermediate variable; in the
third the intermediate result is used inline; and the last one is
basically the same as third, but the function is used as an infix.
On Mon, Jun 27, 2011 at 5:51 PM, Roelof Wobben <[email protected]> wrote:
>
>
> Hello,
>
>
>
> Im stil reading chapter4
>
>
>
> Now we have this : addVectors (x1, y1) (x2, y2) = (x1 + x2, y1 + y2)
>
>
>
> do I understand it that the outcome of x1+x2 will be saved in the last
> expression x1 + x2
>
> But on which variable can the outcome be found.
>
>
>
> Roelof
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
--
Markus L?ll
------------------------------
Message: 4
Date: Mon, 27 Jun 2011 11:35:24 -0400
From: David Place <[email protected]>
Subject: Re: [Haskell-beginners] A first try
To: Manfred Lotz <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Jun 27, 2011, at 9:58 AM, Manfred Lotz wrote:
> Thanks a lot for the suggestion. Works fine.
>
> I only tried deepseq because my first try with seq
>
> let content = xml `seq` parseXMLDoc xml
>
> didn't work.
Have you considered using ByteStrings for your application. There,
hGetContents is strict. Also, you will benefit from more efficient string
operations.
------------------------------
Message: 5
Date: Mon, 27 Jun 2011 15:49:46 +0000
From: Roelof Wobben <[email protected]>
Subject: Re: [Haskell-beginners] Do I understand this well
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
________________________________
> Date: Mon, 27 Jun 2011 16:14:28 +0100
> Subject: Re: [Haskell-beginners] Do I understand this well
> From: [email protected]
> To: [email protected]
>
> No.
>
> You are onfusing defining a function with using it.
>
>
> addVectors (x1, y1) (x2, y2) = (x1 + x2, y1 + y2)
>
> defines the function addVectors
>
> (x, y) = addVectors (3.0, 4.5, -3.4, -5.6)
>
> calls the function, and binds x and y to the components of the result
> (pattern matching).
>
> Alternatively:
>
> fst . addVectors (3.0, 4.5, -3.4, -5.6)
>
> will return the x-compnent of the result (by composing functions)
>
Oke,
I understand that I think
But when I ghci I enter :
(x, y) = addVectors (3.0, 4.5, -3.4, -5.6)
after I made a file with the file defenition.
I get this error :
:1:7 parse error on input =
So something is not right here.
Roelof
------------------------------
Message: 6
Date: Mon, 27 Jun 2011 23:51:45 +0800
From: Lyndon Maydwell <[email protected]>
Subject: Re: [Haskell-beginners] Do I understand this well
To: Roelof Wobben <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8
Top-level bindings are done in ghci with let:
let (x, y) = addVectors (3.0, 4.5, -3.4, -5.6)
On Mon, Jun 27, 2011 at 11:49 PM, Roelof Wobben <[email protected]> wrote:
>
>
>
> ________________________________
>> Date: Mon, 27 Jun 2011 16:14:28 +0100
>> Subject: Re: [Haskell-beginners] Do I understand this well
>> From: [email protected]
>> To: [email protected]
>>
>> No.
>>
>> You are onfusing defining a function with using it.
>>
>>
>> addVectors (x1, y1) (x2, y2) = (x1 + x2, y1 + y2)
>>
>> defines the function addVectors
>>
>> (x, y) = addVectors (3.0, 4.5, -3.4, -5.6)
>>
>> calls the function, and binds x and y to the components of the result
>> (pattern matching).
>>
>> Alternatively:
>>
>> fst . addVectors (3.0, 4.5, -3.4, -5.6)
>>
>> will return the x-compnent of the result (by composing functions)
>>
>
>
> Oke,
>
>
>
> I understand that I think
>
> But when I ghci I enter :
>
>
> (x, y) = addVectors (3.0, 4.5, -3.4, -5.6)
>
>
>
>
>
> after I made a file with the file defenition.
>
> I get this error :
>
>
>
> :1:7 parse error on input =
>
>
>
> So something is not right here.
>
>
>
> Roelof
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 7
Date: Mon, 27 Jun 2011 17:46:58 +0200
From: Manfred Lotz <[email protected]>
Subject: Re: [Haskell-beginners] A first try
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
On Mon, 27 Jun 2011 10:51:03 -0400
David Place <[email protected]> wrote:
>
> On Jun 27, 2011, at 9:58 AM, Manfred Lotz wrote:
>
> >> To ensure that the entire file is read, you can seq on the length,
> >>
> >> xml <- U.hGetContents inh
> >> let content = parseXMLDoc xml
> >> length xml `seq` case content of ...
> >>
> >
> > Thanks a lot for the suggestion. Works fine.
> >
> > I only tried deepseq because my first try with seq
> >
> > let content = xml `seq` parseXMLDoc xml
> >
> > didn't work.
> >
>
> You can call me squeamish, but using a pure function (length) for its
> side-effects seems kind of kludge-y. :-)
>
Yes, I admit it looks strange. :-)
--
Manfred
------------------------------
Message: 8
Date: Mon, 27 Jun 2011 18:38:34 +0200
From: Ertugrul Soeylemez <[email protected]>
Subject: Re: [Haskell-beginners] Doing IO in terms of Arrow
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
Haisheng Wu <[email protected]> wrote:
> I'm wondering if it is possible doing IO in terms of Arrow.
> I got a function search all files under directory recursively and
> I'd like to refartoring using Arrow terms.
Yes, it's possible using Kleisli, but it's not very convenient, because
you need the Kleisli wrapper around everything. Also usually there is
really little reason to do that, because monads are more expressive.
For example they allow you to encode computations with only outputs
directly, without wrapping them in a computation, which takes a stub
argument.
> I tried to define a function like below but failed.
> isDirExist = Kleisli doesDirectoryExist
>
> Do I need to define a instance for IO to be Arrow? Or is there any
> existing solutions?
No, the needed instances are already there, but you need to change your
type signatures:
myGetFilesInDir :: Kleisli FilePath [FilePath]
Greets,
Ertugrul
--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/
------------------------------
Message: 9
Date: Mon, 27 Jun 2011 12:41:42 -0400
From: Mike Meyer <[email protected]>
Subject: Re: [Haskell-beginners] A first try
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8
On Mon, 27 Jun 2011 12:54:51 +0300
Yitzchak Gale <[email protected]> wrote:
> Heinrich Apfelmus wrote:
> > Again, let me stress that the biggest drawback of the Iteratee approach is
> > that you have to rewrite the consumer and cannot reuse ordinary list
> > functions like ?length , words , lines , and so on. But these functions are
> > already lazy, so why not make use of this. (You don't lose anything, every
> > Iteratee can be rewritten as an ordinary function ?String -> IO a ?by using
> > ?`seq` ?in corresponding places.)
> > Here one possibility for a lazier version of ?withFile' :
Very nice. I hope you don't mind if I use it?
I've been watching this thread closely, because one of my concerns for
my first project is making sure the file IO gets handled right. It's
processing a set of files in order (typical Unix command line stuff),
and I came up with two requirements:
1) Only the file currently being processed should be open.
2) Don't read the entire file into memory at once.
You seem to have hit both of them.
> Let me just add my voice in support of Heinrich.
Ditto.
> Whether you are using lazy IO or Iteratees, we really need
> some better higher-level combinators with simpler semantics
> for more of the common use cases. Then it won't really matter.
And that was my conclusion last night. Iteratees provide generalized
tools that don't seem to have obvious ways to do common
operations. While that kind of thing is needed, I suspect that over
90% of file processing (at least for command line arguments) could be
handled by things like Heinrich's withFiles and the obvious variants
of the HOF list functions, like:
fileMap :: (String -> a) -> [FilePath] -> [a]
fileFoldl' :: (a -> String -> a) -> a -> [FilePath] -> a
The user doesn't care whether it's using lazy IO or iteratees, so
long as it has the proper semantics.
<mike
--
Mike Meyer <[email protected]> http://www.mired.org/
Independent Software developer/SCM consultant, email for more information.
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
------------------------------
Message: 10
Date: Mon, 27 Jun 2011 18:40:32 +0200
From: Ertugrul Soeylemez <[email protected]>
Subject: Re: [Haskell-beginners] Would you shed light on "undefined
values" please?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
Brent Yorgey <[email protected]> wrote:
> > Bottom arises, as soon as a language is total. This is related to
> > the halting problem. Bottom is the value, which is never computed
> > in the sense that it never results. Only nontotal languages (like
> > Agda) can prevent bottom values from appearing.
>
> That is a funny use of the word "total"; I think you mean
> "Turing-complete". "Total" is usually used of languages in which it
> is only possible to define total functions -- such as Agda. Haskell
> is non-total since it is possible to define non-total, i.e. partial,
> functions, which are undefined for some inputs.
Indeed, i flipped the meanings. =)
Greets,
Ertugrul
--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 36, Issue 73
*****************************************