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: main (Brent Yorgey)
2. redirect stdout to /dev/null (Hong Yang)
3. Re: redirect stdout to /dev/null (Magnus Therning)
4. parse error (John Moore)
5. Re: parse error (informationen)
6. Re: parse error (Felipe Lessa)
7. string instead of char (John Moore)
8. Re: string instead of char (Colin Paul Adams)
9. Re: string instead of char (Robert Ziemba)
----------------------------------------------------------------------
Message: 1
Date: Sat, 3 Oct 2009 16:27:13 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] main
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Sat, Oct 03, 2009 at 08:07:50PM +0100, John Moore wrote:
> Hi,
> I must be doing something wrong when I run a program it comes up on the
> screen as OK module loaded Main
> *Main>
> But it will not do what I program to do. What do I enter after *main> I
> tried putting in the arguments but ot just returns the arguments.
> For example:
>
> signum x | x < 0 = -1
> | x == 0 = 0
> | x > 0 = 1
If you have the above in a file and load it into ghci, it just means
that now the function 'signum' is available for use. You type
expressions at the ghci prompt, so if you type 5 by itself, that is
just the expression 5, which of course has the value... 5. =) If you
want to evaluate signum with an input you must type, for example,
signum 5
However, I should warn you that the Haskell Prelude already defines a
function called 'signum', so if you load the above and type 'signum 5'
it will give you an error about signum being ambiguous (it does not
know which one you want, the one from the Prelude or the one you
defined in the file you loaded). There are various ways around this,
but the easiest for now is probably just to use a different name for
your function.
-Brent
------------------------------
Message: 2
Date: Sat, 3 Oct 2009 16:43:25 -0500
From: Hong Yang <[email protected]>
Subject: [Haskell-beginners] redirect stdout to /dev/null
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
On UNIX, we can easily redirect stdout to /dev/null in a Shell. How is this
realized in Haskell on both UNIX and Windows?
I used a library which gave me unwanted stdout display. I tried to find any
function to hide the stdout output, but could not. Can someone help me out?
Otherwise I have to modify the code in the library to comment out some print
commands.
Thanks,
Hong
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20091003/789b18fb/attachment-0001.html
------------------------------
Message: 3
Date: Sun, 4 Oct 2009 06:56:55 +0100
From: Magnus Therning <[email protected]>
Subject: Re: [Haskell-beginners] redirect stdout to /dev/null
To: [email protected]
Message-ID: <20091004055655.ga19...@tatooine>
Content-Type: text/plain; charset="utf-8"
On Sat, Oct 03, 2009 at 04:43:25PM -0500, Hong Yang wrote:
> On UNIX, we can easily redirect stdout to /dev/null in a Shell. How is this
> realized in Haskell on both UNIX and Windows?
I'm not sure about Windows, but in Unix you'd close stdout, open /dev/null and
then call dup2() (System.Posix.IO.dupTo) to duplicate the newly opened Fd to
stdout (1).
> I used a library which gave me unwanted stdout display. I tried to find any
> function to hide the stdout output, but could not. Can someone help me out?
>
> Otherwise I have to modify the code in the library to comment out some print
> commands.
I would strongly encourage you to modify the library. It can be argued that
it's rather poor library design to not let the user control where output goes.
/M
--
Magnus Therning (OpenPGP: 0xAB4DFBA4)
magnusï¼ therningï¼org Jabber: magnusï¼ therningï¼org
http://therning.org/magnus identi.ca|twitter: magthe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
Url :
http://www.haskell.org/pipermail/beginners/attachments/20091004/d01b6f26/attachment-0001.bin
------------------------------
Message: 4
Date: Sun, 4 Oct 2009 14:43:35 +0100
From: John Moore <[email protected]>
Subject: [Haskell-beginners] parse error
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hi,
This is a function that returns true if divisible by 2. But it keeps
telling me parse error on input | . What is wrong here.
is_even n | mod n 2 == 0
| True
Not sure if I need another statement for false
John
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20091004/a11ce3e0/attachment-0001.html
------------------------------
Message: 5
Date: Sun, 4 Oct 2009 16:11:35 +0200
From: informationen <[email protected]>
Subject: Re: [Haskell-beginners] parse error
To: John Moore <[email protected]>
Cc: [email protected]
Message-ID: <20091004141135.gb3...@debian>
Content-Type: text/plain; charset=iso-8859-15; format=flowed
Hi,
the "| True" part is wrong. It should read:
is_even n | n `mod` 2 == 0 = True
| otherwise = False.
Kind regards
Chris
>Hi,
> This is a function that returns true if divisible by 2. But it keeps
>telling me parse error on input | . What is wrong here.
>is_even n | mod n 2 == 0
> | True
>
>Not sure if I need another statement for false
>
>John
>_______________________________________________
>Beginners mailing list
>[email protected]
>http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 6
Date: Sun, 4 Oct 2009 11:35:55 -0300
From: Felipe Lessa <[email protected]>
Subject: Re: [Haskell-beginners] parse error
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Sun, Oct 04, 2009 at 04:11:35PM +0200, informationen wrote:
> the "| True" part is wrong. It should read:
>
> is_even n | n `mod` 2 == 0 = True
> | otherwise = False.
Which means that is_even may be expressed as
is_even n = n `mod` 2 == 0
Equivalently, in C the first code would be
int is_even(int n) {
if (n % 2 == 0)
return 1;
else
return 0;
}
while the code I presented above would be
int is_even(int n) {
return (n % 2 == 0);
}
HTH,
--
Felipe.
------------------------------
Message: 7
Date: Sun, 4 Oct 2009 17:05:33 +0100
From: John Moore <[email protected]>
Subject: [Haskell-beginners] string instead of char
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hi,
I am now writing a function that replaces vowels with the letter x.
eg.put in a string "help" and out comes hxlp.
I tried this:
f x = case x of
{'a' -> 'x';'e' -> 'x';'i' -> 'x';'o' -> 'x';'u' -> 'x';_ -> x}
but this wont work on strings, only on the individual letters. Any direction
would be very welcome.
Yours
john
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20091004/a727e5c8/attachment-0001.html
------------------------------
Message: 8
Date: Sun, 04 Oct 2009 17:10:39 +0100
From: Colin Paul Adams <[email protected]>
Subject: Re: [Haskell-beginners] string instead of char
To: John Moore <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
>>>>> "John" == John Moore <[email protected]> writes:
John> Hi, I am now writing a function that replaces vowels with
John> the letter x. eg.put in a string "help" and out comes hxlp.
John> I tried this:
John> f x = case x of
John> {'a' -> 'x';'e' -> 'x';'i' -> 'x';'o' -> 'x';'u' ->
John> 'x';_ -> x}
John> but this wont work on strings, only on the individual
John> letters. Any direction would be very welcome.
You need to call
map f "whatever"
where f is your function for replacing a character (as above).
--
Colin Adams
Preston Lancashire
------------------------------
Message: 9
Date: Sun, 4 Oct 2009 11:55:05 -0700
From: Robert Ziemba <[email protected]>
Subject: Re: [Haskell-beginners] string instead of char
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
You can also do something like this instead of the case statement (this is
using GHCI).
Prelude> let exclude = ['a', 'e', 'i', 'o', 'u']
Prelude> let f excl letter | letter `elem` excl = 'x' | otherwise = letter
Prelude> map (f exclude) "hello"
"hxllx"
Rob Ziemba
On Sun, Oct 4, 2009 at 9:10 AM, Colin Paul Adams
<[email protected]>wrote:
> >>>>> "John" == John Moore <[email protected]> writes:
>
> John> Hi, I am now writing a function that replaces vowels with
> John> the letter x. eg.put in a string "help" and out comes hxlp.
> John> I tried this:
>
> John> f x = case x of
>
> John> {'a' -> 'x';'e' -> 'x';'i' -> 'x';'o' -> 'x';'u' ->
> John> 'x';_ -> x}
>
> John> but this wont work on strings, only on the individual
> John> letters. Any direction would be very welcome.
>
> You need to call
>
> map f "whatever"
>
> where f is your function for replacing a character (as above).
> --
> Colin Adams
> Preston Lancashire
> _______________________________________________
> 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/20091004/68b6b7a0/attachment.html
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 16, Issue 2
****************************************