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. Offside rule for function arguments? (John Smith)
2. Sections in Class definition (John Smith)
3. hGetContents (Luca Ciciriello)
4. Re: hGetContents (David Virebayre)
5. Re: Offside rule for function arguments? (Brent Yorgey)
6. Re: Sections in Class definition (Brent Yorgey)
7. Re: Offside rule for function arguments?
(Jonas Almstr?m Dureg?rd)
8. Re: Offside rule for function arguments? (John Smith)
9. Re: Re: Offside rule for function arguments?
(Jonas Almstr?m Dureg?rd)
----------------------------------------------------------------------
Message: 1
Date: Mon, 23 Aug 2010 09:33:13 +0300
From: John Smith <[email protected]>
Subject: [Haskell-beginners] Offside rule for function arguments?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Why doesn't Haskell allow something like this?
fac 0 = 0
1 = 1
x = x * fac (x-1)
This would be clearer than repeating the function name each time, and follow
the same pattern as guards and case.
------------------------------
Message: 2
Date: Mon, 23 Aug 2010 10:28:38 +0300
From: John Smith <[email protected]>
Subject: [Haskell-beginners] Sections in Class definition
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
I tried to reproduce the definition of Eq with
class Eq a where
(==), (/=) :: a -> a -> Bool
(/=) = not (==)
(==) = not (/=)
and got
Couldn't match expected type `Bool'
against inferred type `a1 -> a1 -> Bool'
In the first argument of `not', namely `(==)'
In the expression: not (==)
In the definition of `/=': /= = not (==)
Couldn't match expected type `Bool'
against inferred type `a1 -> a1 -> Bool'
In the first argument of `not', namely `(/=)'
In the expression: not (/=)
In the definition of `==': == = not (/=)
What have I done wrong? Is it not possible to define Eq in point-free style?
------------------------------
Message: 3
Date: Mon, 23 Aug 2010 09:26:06 +0100
From: Luca Ciciriello <[email protected]>
Subject: [Haskell-beginners] hGetContents
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
I all.
I'm reading a txt file using the code
inh <- openFile "myfile.txt" ReadMode
contents <- hGetContents inh
On Windows all works fine. I'm able to read the file without any problems.
On Mac OS X (10.6.4), with the same txt file and the same code above, I get the
exception:
hGetContents: invalid argument (Illegal byte sequence).
In both the systems (Mac and Windows) I've installed the same Haskell platform
2010.2.0.0 (GHC 6.12.3).
Any idea why I've this behaviour on Mac system?
Thanks in advance for any answer.
Luca.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100823/0d396304/attachment-0001.html
------------------------------
Message: 4
Date: Mon, 23 Aug 2010 10:32:46 +0200
From: David Virebayre <[email protected]>
Subject: Re: [Haskell-beginners] hGetContents
To: Luca Ciciriello <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
2010/8/23 Luca Ciciriello <[email protected]>:
> I all.
> I'm reading a txt file using the code
> inh <- openFile "myfile.txt" ReadMode
> contents <- hGetContents inh
> On Windows all works fine. I'm able to read the file without any problems.
> On Mac OS X (10.6.4), with the same txt file and the same code above, I get
> the exception:
> hGetContents: invalid argument (Illegal byte sequence).
> In both the systems (Mac and Windows) I've installed the same Haskell
> platform 2010.2.0.0 (GHC 6.12.3).
> Any idea why I've this behaviour on Mac system?
> Thanks in advance for any answer.
Perhaps a missmatch between the file's encoding (utf8, iso-8859-1,
etc) and your system's locale settings.
David.
------------------------------
Message: 5
Date: Mon, 23 Aug 2010 10:15:25 +0100
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Offside rule for function arguments?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Mon, Aug 23, 2010 at 09:33:13AM +0300, John Smith wrote:
> Why doesn't Haskell allow something like this?
>
> fac 0 = 0
> 1 = 1
> x = x * fac (x-1)
>
> This would be clearer than repeating the function name each time,
> and follow the same pattern as guards and case.
Good question. I don't know of any particular reason.
-Brent
------------------------------
Message: 6
Date: Mon, 23 Aug 2010 10:21:52 +0100
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Sections in Class definition
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Mon, Aug 23, 2010 at 10:28:38AM +0300, John Smith wrote:
> I tried to reproduce the definition of Eq with
>
> class Eq a where
> (==), (/=) :: a -> a -> Bool
>
> (/=) = not (==)
> (==) = not (/=)
Consider the type of not:
not :: Bool -> Bool
And the type of (==):
(==) :: Eq a => a -> a -> Bool
You are providing (==) as the argument to not, but this will not work,
since not expects an argument of type Bool and (==) does not have type
Bool (it has type a -> a -> Bool). This is what the error message is
telling you.
It is possible to define these in a point-free style, but I would not
recommend it:
(/=) = (not .) . (==)
Is it obvious to you what this definition does, and how it works? Me
neither. A little better would be something like
oo f g x y = f (g x y)
(/=) = not `oo` (==)
But I still prefer the nice and simple
x /= y = not (x == y)
-Brent
------------------------------
Message: 7
Date: Mon, 23 Aug 2010 11:32:45 +0200
From: Jonas Almstr?m Dureg?rd <[email protected]>
Subject: Re: [Haskell-beginners] Offside rule for function arguments?
To: Brent Yorgey <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Maybe because of this:
function 0 = 0 where
fun 1 = 1
2 = 2
The last declaration (2=2) can define either fun or function. I'm not saying
this is a major problem, but there may be other problems like these.
/J
On 23 August 2010 11:15, Brent Yorgey <[email protected]> wrote:
> On Mon, Aug 23, 2010 at 09:33:13AM +0300, John Smith wrote:
>> Why doesn't Haskell allow something like this?
>>
>> fac 0 = 0
>> 1 = 1
>> x = x * fac (x-1)
>>
>> This would be clearer than repeating the function name each time,
>> and follow the same pattern as guards and case.
>
> Good question. I don't know of any particular reason.
>
> -Brent
> _______________________________________________
> 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/20100823/2bb1e23e/attachment-0001.html
------------------------------
Message: 8
Date: Mon, 23 Aug 2010 12:46:32 +0300
From: John Smith <[email protected]>
Subject: [Haskell-beginners] Re: Offside rule for function arguments?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
The indentation on the second line would generate a parse error, the same as it
does now.
On 23/08/2010 12:32, Jonas Almström Duregård wrote:
> Maybe because of this:
>
> function 0 = 0 where
> fun 1 = 1
> 2 = 2
>
> The last declaration (2=2) can define either fun or function. I'm not saying
> this is a major problem, but there may be
> other problems like these.
>
> /J
>
> On 23 August 2010 11:15, Brent Yorgey <[email protected]
> <mailto:[email protected]>> wrote:
> > On Mon, Aug 23, 2010 at 09:33:13AM +0300, John Smith wrote:
> >> Why doesn't Haskell allow something like this?
> >>
> >> fac 0 = 0
> >> 1 = 1
> >> x = x * fac (x-1)
> >>
> >> This would be clearer than repeating the function name each time,
> >> and follow the same pattern as guards and case.
> >
> > Good question. I don't know of any particular reason.
> >
> > -Brent
------------------------------
Message: 9
Date: Mon, 23 Aug 2010 11:52:22 +0200
From: Jonas Almstr?m Dureg?rd <[email protected]>
Subject: Re: [Haskell-beginners] Re: Offside rule for function
arguments?
To: John Smith <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
> The indentation on the second line would generate a parse error, the same
as it does now.
What parser error is that? Both
function 0 = 0 where
fun 1 = 1
function 2 = 2
and
function 0 = 0 where
fun 1 = 1
fun 2 = 2
works for me.
/J
On 23 August 2010 11:46, John Smith <[email protected]> wrote:
> The indentation on the second line would generate a parse error, the same
> as it does now.
>
>
> On 23/08/2010 12:32, Jonas Almström Duregård wrote:
>
>> Maybe because of this:
>>
>> function 0 = 0 where
>> fun 1 = 1
>> 2 = 2
>>
>> The last declaration (2=2) can define either fun or function. I'm not
>> saying this is a major problem, but there may be
>> other problems like these.
>>
>> /J
>>
>> On 23 August 2010 11:15, Brent Yorgey <[email protected] <mailto:
>> [email protected]>> wrote:
>> > On Mon, Aug 23, 2010 at 09:33:13AM +0300, John Smith wrote:
>> >> Why doesn't Haskell allow something like this?
>> >>
>> >> fac 0 = 0
>> >> 1 = 1
>> >> x = x * fac (x-1)
>> >>
>> >> This would be clearer than repeating the function name each time,
>> >> and follow the same pattern as guards and case.
>> >
>> > Good question. I don't know of any particular reason.
>> >
>> > -Brent
>>
>
> _______________________________________________
> 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/20100823/40aab87d/attachment.html
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 26, Issue 44
*****************************************