Re: gcd 0 0 = 0

2001-12-18 Thread Marc van Dongen

Lars Henrik Mathiesen ([EMAIL PROTECTED]) wrote:

: > Alan Bawden ([EMAIL PROTECTED]) wrote:
: > : Indeed, that's a nice way of putting it.  How about if the report just
: > : says:
: > : 
: > :In order to make the non-negative integers into a lattice under `gcd'
: > :and `lcm', we define `gcd 0 0 = 0'.

[snip]

: This is exactly what you get if you plug the relation 'divides' on the
: non-negative integers into the definition of meet in a lattice. So
: this formulation is no more or less complex to use than the lattice
: one --- and people who do know about lattices will probably realize
: this pretty fast.

I disagree. Alan is talking about adding things to the haskell report.
That document should be accessible to as many people as possible.
I have not yet met anybody who had lattice theory in primary and/or
secondary school. On the other hand I *have* met quite a few of them
who have a pretty good idea about what it means for one number to
divide another.

[snip]

Regards,


Marc van Dongen
-- 
Marc van Dongen | [EMAIL PROTECTED] |
Computer Science Department | Western Road | () ASCII ribbon campaign
University College Cork |Cork, Ireland | /\ against HTML mail
phone: +353 (0)21 4903578   | fax: 4903113 |

___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell



Re: gcd 0 0 = 0

2001-12-18 Thread Marc van Dongen

Alan Bawden ([EMAIL PROTECTED]) wrote:

:In case it isn't clear already, these definitions make a lattice on
:the positive integers, with divides ~ leq, gcd ~ meet and lcm ~ join,
:using the report's definitions of gcd and lcm.
: 
: Indeed, that's a nice way of putting it.  How about if the report just
: says:
: 
:In order to make the non-negative integers into a lattice under `gcd'
:and `lcm', we define `gcd 0 0 = 0'.

It would surely make things a lot less accessible to people (including
me) who do not have any (or limited) knowledge about lattices. Why not
make it more accessible and use the following rule (ore something similar)?
The greates common divison (gcd) of two integers a and b is the unique
non-negative integer g which has each of the following two properties:
 1) g divides both a and b; and
 2) if g' also divides both a and b then g' also divides g,
Here an integer a divides an integer b if there is an integer c
such that b = c*a.

Note that if you regard an integer a to be greater than another
integer b if b divides a then the gcd of two intgerers may also
be regarded as the greatest common divisor of a and b.

Regards,


Marc van Dongen

___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell



Re: gcd 0 0 = 0

2001-12-18 Thread Marc van Dongen

Ch. A. Herrmann ([EMAIL PROTECTED]) wrote:

: In contrast, 0*x=0, thus 0 "divides" 0 (somehow).
: But I have problems with "gcd being the greatest positive integer ..."

[snip]

: - 0 is not positive, it is non-negative or natural
: - 2 also divides 0 and 2 is a "greater integer" than 0
:   (0 is the top element of the lattice formed by the division relation
:but that is not clear by the expression "greatest")
: 

gcd a b is the greatest non-negative integer dividing both a
and b such that anything that divides both a and b also divides
gcd a b (so gcd a b is the greatest thing that divides both a
and b).

Regards,


Marc van Dongen
-- 
Marc van Dongen | [EMAIL PROTECTED] |
Computer Science Department | Western Road | () ASCII ribbon campaign
University College Cork |Cork, Ireland | /\ against HTML mail
phone: +353 (0)21 4903578   | fax: 4903113 |

___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell



Re: gcd 0 0 = 0

2001-12-16 Thread Marc van Dongen

Marc van Dongen ([EMAIL PROTECTED]) wrote:

:   An integer $a$ divides integer $b$ if there exists an integer
:   $c$ such that $a c= b$.

[snip]

:  gcd 0 0 = 0; and
:  gcd 0 0 /= error "Blah"

To make clear why $0$ (and not any other non-zero integer) is the
gcd of $0$ and $0$ I should have added that for the integer case
$g$ is called a greatest common divisor (gcd) of $a$ and $b$ if it
satifies each of the following two properties:

 1) $g$ divides both $a$ and $b$;
 2) if $g'$ is a common divisor of $a$ and $b$ then $g'$ divides $g$.

First notice that $0$ is a gcd of $0$ and $0$ because of the following:
 *) $0$ divides $0$ (and divides $0$);
 *) whenever $g'$ is an integer that divides $0$ and divides $0$
then $g'$ divides $0$.

Next notice that if $g$ is any non-zero integer then $g$ cannot be
a gcd of $0$ and $0$ because $0$ (a common divisor of $0$ and $0$)
does not divide $g$.

Finally, observe that this makes $0$ the unique gcd of $0$ and $0$.

: The gcd of two integers is usually defined as a non-negative
: number to make it unique.


Regards,


Marc van Dongen

___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell



Re: gcd 0 0 = 0

2001-12-14 Thread Marc van Dongen

Simon Peyton Jones ([EMAIL PROTECTED]) wrote:

: If someone could write a sentence or two to explain why gcd 0 0 = 0,
: (ideally, brief ones I can put in the report by way of explanation),
: I think that might help those of us who have not followed the details
: of the discussion.  

Division in the context of gcds (of integers) is usually defined
along the lines of:
  An integer $a$ divides integer $b$ if there exists an integer
  $c$ such that $a c= b$.
Note that here division is a *relation* an not a *function*/*operator*.
Given the definition of division being a relation it makes perfect
sense to say that $0$ divides $0$ which is why
 gcd 0 0 = 0; and
 gcd 0 0 /= error "Blah"
The gcd of two integers is usually defined as a non-negative
number to make it unique.

HTH.

PS: I am strongly in favour of gcd 0 0 = 0.

Regards,


Marc van Dongen

___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell



Re: code for exercise 4.10

2001-10-11 Thread Marc van Dongen

rock dwan ([EMAIL PROTECTED]) wrote:

: Iam having some difficulties doing exercise 4.10 from craft of fucntional 
: programming book ..is their a possible solution for this ?

Can we please move this thread to the haskell cafe?

Thanks in advance,


Marc van Dongen

___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell



Re: computer language shootout

2001-07-27 Thread Marc van Dongen

Miles Egan ([EMAIL PROTECTED]) wrote:

[shootout]

Before it starts to explode, can we move 
this thread to the Haskell Cafe?

Regards,


Marc

-- 
 Marc van Dongen, CS Dept | phone:  +353 21 4903578
University College Cork, NUIC | Fax:+353 21 4903113
  Western Road, Cork, Ireland | Email: [EMAIL PROTECTED]

___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell



Two Times [was Re: Happy and Macros (was Re: ANNOUNCE: Happy 1.10 released)]

2001-05-11 Thread Marc van Dongen

Manuel M. T. Chakravarty ([EMAIL PROTECTED]) wrote:

[received message twice]

Am I just the only one or does everybody receive
messages posted to [EMAIL PROTECTED] and
[EMAIL PROTECTED] twice? I find
it a bit (I know I am exaggerating) annoying.
Is there a way to avoid this?


Regards,


Marc

___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell



Re: Help about programming a module in haskell ?

2001-04-18 Thread Marc van Dongen

Mickaël GAUTIER ([EMAIL PROTECTED]) wrote:

: Hi, i am a french beginner in programming in haskell language. My first module 
:was to prove that a boolean proposition is always right. So it was about logical 
:mathematic. Now i am trying to program a modul which function not with mathematic 
:rules but with logical rules as in Prolog. I've a game named nani (it's a boy who 
:wants to find his nani which is in one of the three rooms of the house) wrote in 
:prolog and i'm trying to convert it in haskell. If someone is interest by my subject 
:can he send me his e-mail adress ?
: Thanks Mickaël GAUTIER

Hi,


There is a Prolog module for Haskell but when
I tried to locate it I couldn't find it. Perhaps
somebody can help.


Regards,


Marc van Dongen
-- 
 Marc van Dongen, CS Dept | phone:  +353 21 4903578
University College Cork, NUIC | Fax:+353 21 4903113
  College Road, Cork, Ireland | Email: [EMAIL PROTECTED]

___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell



Re: `Covertible' class. Reply.

2001-02-08 Thread Marc van Dongen

S.D.Mechveliani ([EMAIL PROTECTED]) wrote:

[snip]

: The basic algebra library BAL 
:  http://www.botik.ru/pub/local/Mechveliani/basAlgPropos/bal-pre-0.01/
:  
: suggests class Cast a b where cast :: a -> b -> a

I just want to add that this is almost similar to a
mechanism I've implemented. You really need this.

Regards,


Marc van Dongen

___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell



Re: Group theory

2000-10-24 Thread Marc van Dongen

Eric Allen Wohlstadter ([EMAIL PROTECTED]) wrote:

: Are there any Haskell libraries or programs related to group theory? I am
: taking a class and it seems like Haskell would be a good programming
: language for exploring/reasoning about group theory. What I had in mind
: was perhaps you could have a function which takes a list(set) and a
: function with two arguments(binary operator) and checks to see whether or
: not it is a group. I think it might be a fun exercies to write myself but
: I'd like to see if it's already been done or what you guys think about it.

I think Sergey Mechveliani's docon (algebraic DOmain CONstructor)
has facilities for that. Have a look at:

http://www.cs.bell-labs.com/who/wadler/realworld/docon.html


Regards,


Marc van Dongen

___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell



Prelude in LaTeX

2000-07-05 Thread Marc van Dongen

Hello all,

Is there anybody who knows where to find the
Prelude typeset in Manuel Chakravarty's
haskell.sty?

Thanks in advance for any replies.

Regards,


Marc van Dongen
-- 
 Marc van Dongen, CS Dept | phone:  +353 21 4903578
University College Cork, NUIC | Fax:+353 21 4903113
  College Road, Cork, Ireland | Email: [EMAIL PROTECTED]




Re: static evaluation of dynamics thing

2000-05-20 Thread Marc van Dongen

Simon Peyton Jones ([EMAIL PROTECTED]) wrote:

[static]
 
: said, some functions are legitimately bottom.  But think about assertions:
: 
:   f x = assert (p x) (...x...)
: 
: where assert :: Bool -> a -> a

I like that. Also I would like a
assertAndBelieveMe which could be used to as in:

quot' a b | assertAndBelieveMe (b /= 0) = quot a b

So that a special version of quot could be used
which would not check for b == 0.
 
: Life is short.  Are these features that would be useful to lots of people?

Yes please.

Regards,


Marc van Dongen




Re: sample argument. Dongen's example

2000-05-08 Thread Marc van Dongen

S.D.Mechveliani ([EMAIL PROTECTED]) wrote:

  [I cc'd this to haskell as well]
 
: this is exactly the Domain conversion proposal, described in
: basAlgPropos.  class Cast a b where cast :: a -> b -> a.
: The first argument is the sample for domain. The second casts to
: `a' after the given sample. For example  cast (x^2+y (in Z[x,y)) 2
: maps 2 to polynomial in x,y 
: - if the  instance Cast (Pol ..) Integer
: is defined.
  
I knew you must have had something to obtain a 
similar functionality this as well. It is needed.
 
 
Regards, 
 
 
Marc 




[dongen@cs.ucc.ie: Re: sample argument. Dongen's example]

2000-05-08 Thread Marc van Dongen

Sorry about this. I thought I group replied when
replied Sergey's e-mail.

-- 
 Marc van Dongen, CS Dept | phone:  +353 21 4903578
University College Cork, NUIC | Fax:+353 21 4903113
  College Road, Cork, Ireland | Email: [EMAIL PROTECTED]

- Forwarded message from Marc van Dongen <[EMAIL PROTECTED]> -

Date: Mon, 8 May 2000 11:14:03 +0100
From: Marc van Dongen <[EMAIL PROTECTED]>
To: "S.D.Mechveliani" <[EMAIL PROTECTED]>
Subject: Re: sample argument. Dongen's example
X-Mailer: Mutt 1.0.1i
In-Reply-To: <[EMAIL PROTECTED]>; from [EMAIL PROTECTED] on Mon, May 
08, 2000 at 01:16:09PM +0400

S.D.Mechveliani ([EMAIL PROTECTED]) wrote:

: Looks like it uses the sample argument. This  p  contains the 
: parameters that describe a polynomial domain  P = c[x1..xn].
: Different ways to order the monomial set, different lists of 
: "variables" may mean different domains inside the *same type*.
: If  p  contains variables  ["x"],  p' contains ["x","y"],
: then   zero p  and  zero p'  
: 
: have to be zeroes of very different domains corresponding to 
:  p, p' :: a.
: If you rely on the features like this, this is the very sample 
: argument approach.
: Do you mean this?

No. I meant that I didn't understand the second sentence above the
one where I started my reply:-)
 
: Classic Haskell approach:
: -

[]
 
: Besides several technical hindrances of mathematical nature, it 
: puts certain principal restriction.
: It prohibits all the mathematical practice of dynamic change of
: orderings, variable lists, residue domains for different base, 
: generally - dynamic change of computation domain given by
: *parameter*.

Exactly. This has been a *great* pain in the neck for me when
writing operations on polynomials using standard notation which
alowed for the hiding of the additional information needed to
implement fast algorithms.

[...]

: I suggest now         zero :: a -> a  

 or constant :: a -> c ->

Regards,

Marc van Dongen
-- 
 Marc van Dongen, CS Dept | phone:  +353 21 4903578
University College Cork, NUIC | Fax:+353 21 4903113
  College Road, Cork, Ireland | Email: [EMAIL PROTECTED]

- End forwarded message -




Re: sample argument. Dongen's example

2000-05-08 Thread Marc van Dongen

S.D.Mechveliani ([EMAIL PROTECTED]) wrote:

: I wrote to list, and you reply privately.

Ooops. I thought I group replied. I'll forward to
the list.

: I think that it is good for the list to know that someone else
: appreciates the need of dynamic parameters in domain ...

Which is why I decided to add something to the discussion.

: But I an dumb at your> or constant :: a -> c ->
: 
: For example,  zero (2,3) = (0,0)   gives zero for  Int x Int.
: And how to use `constant' ?

Say you have a constant c in some ring k and you want to
lift it (I think that's the proper term) to the polynomial
ring k[X] then you can if you have a polynomial, say p, in
k[X] already. Just use: constant p c.


Regards,


Marc
-- 
 Marc van Dongen, CS Dept | phone:  +353 21 4903578
University College Cork, NUIC | Fax:+353 21 4903113
  College Road, Cork, Ireland | Email: [EMAIL PROTECTED]




Re: basAlgPropos. Why sample argument

2000-05-07 Thread Marc van Dongen

Fergus Henderson ([EMAIL PROTECTED]) wrote:

[snip]
 
: >   * `zero x'  fits the aim of implicit dynamic domains.
: 
: This one is much more interesting.

I am not sure if I understand this but I also used
 zero :: a -> a
to create polynopmials as opposed to a function
 zero :: a
The application
 zero p
created a zero polynomial with certain ``built-in''
properties like a term-order it inherited from p.


Regards,


Marc van Dongen
-- 
 Marc van Dongen, CS Dept | phone:  +353 21 4903578
University College Cork, NUIC | Fax:+353 21 4903113
  College Road, Cork, Ireland | Email: [EMAIL PROTECTED]




Re: doubly linked list

2000-04-28 Thread Marc van Dongen

Jerzy Karczmarczuk ([EMAIL PROTECTED]) wrote:

: But in Haskell, where the beasts are not mutable:
: 
: ... Actually, has anybody really used them for practical purposes?

I have used doubly linked lists in Haskell about four
years ago to implement a queue from which objects could
be added at front/back and deleted anywhere.

A mutable array was used to see if objects were in the queue.
If they were then (Just Ix) to them would be returned
and if they weren't Nothing. The index could then be used
to find the possible previous and next elements in the queue
and change their representations. I cheated a bit because I used
the fact that the possible indices were know in advance so that
I could use an array to represent the member in the queue as
well. It worked well.

I've appended (what I think are the most important) code-fragments
at the end. I don't know if I would do it the same way again; this
was years ago.

Regards,


Marc van Dongen

> initQueue :: Ix i => (LinkedList s i v) -> [(i,v)] -> ST s (Maybe i,Maybe i)
> initQueue _ []
>   = return (Nothing,Nothing)
> initQueue marks ((i,v):ivs)
>   = writeArray marks i (Nothing,Nothing,Just v) >>
> a2q marks i i ivs

> addToQueue :: Ix i =>
>   (LinkedList s i v)
>  -> (Maybe i)
>  -> (Maybe i)
>  -> [(i,v)]
>  -> ST s (Maybe i,Maybe i)
> addToQueue marks fst lst  []
>   = return (fst,lst)
> addToQueue marks Nothing_  ijrs
>   = initQueue marks ijrs
> addToQueue marks (Just fst) (Just lst) ijrs
>   = a2q marks fst lst ijrs

> a2q :: Ix i =>
>   (LinkedList s i v)
>   -> i
>   -> i
>   -> [(i,v)]
>   -> ST s (Maybe i,Maybe i)
> a2q _ fst lst []
>   = return (Just fst,Just lst)
> a2q marks fst lst ((i,v):ivs)
>   = readArray marks i >>= \(_,_,mbv) ->
> case mbv of
>   Nothing -> readArray marks lst  >>= \(jpred,_,jv) ->
>  writeArray marks lst (jpred,Just i,jv)   >>
>  writeArray marks i (Just lst,Nothing,Just v) >>
>  a2q marks fst i ivs
>   _   -> a2q marks fst lst ivs

> delFromQueue :: Ix i =>
>   (LinkedList s i v)
>   -> (Maybe i)
>   -> (Maybe i)
>   -> [i]
>   -> ST s (Maybe i,Maybe i)
> delFromQueue _  jfstjlst[]
>   = return (jfst,jlst)
> delFromQueue marks  jfst@(Just fst) jlst@(Just lst) (i:is)
>   = readArray marks i  >>= 
>\(jpred,jsucc,_) ->
> writeArray marks i (Nothing,Nothing,Nothing)   >>
> case jpred of
>   Nothing  -> case jsucc of
> Nothing  -> return (Nothing,Nothing)
> (Just s) -> readArray marks s  >>= \(_,s',r') ->
> writeArray marks s (Nothing,s',r') >>
> delFromQueue marks jsucc jlst is
>   (Just p) -> case jsucc of
> Nothing  -> readArray marks p  >>= \(p',_,r') ->
> writeArray marks p (p',Nothing,r') >>
> delFromQueue marks jfst jpred is
> (Just s) -> readArray marks p  >>= \(p',_,r') ->
> writeArray marks p (p',jsucc,r')   >>
> readArray marks s  >>= \(_,s',r') ->
> writeArray marks s (jpred,s',r')   >>
> delFromQueue marks jfst jlst is




Re: libraries for Integer

2000-04-19 Thread Marc van Dongen

George Russell ([EMAIL PROTECTED]) wrote:


[...]

: Sorry I can't be more helpful.  But there is unlikely to be a simple
: answer to the question "Does LIP or GMP multiply numbers fastest?";
: it will depend on how big the numbers are, what platform you are using,
: and how much difficult the interface is to use.  (GMP is faster if

Thanks anyway.

[...]

Regards,

Marc




Re: libraries for Integer

2000-04-19 Thread Marc van Dongen

George Russell ([EMAIL PROTECTED]) wrote:

: I agree actually.  Integer only needs to be an implementation of
: multiprecision arithmetic; we shouldn't tie it to GMP.  There are
: other multiprecision arithmetic packages out there, for example

But it is pretty fast.

: the LIP package included in NTL
:http://www.shoup.net/ntl/

Do you have any data about comparisons with this or
other packages?

Regards,


Marc van Dongen
-- 
 Marc van Dongen, CS Dept | phone:   +353 21 903578
University College Cork, NUIC | Fax: +353 21 903113
  College Road, Cork, Ireland | Email: [EMAIL PROTECTED]




Re: Type signatures in instance declarations?

2000-04-10 Thread Marc van Dongen

Koen Claessen ([EMAIL PROTECTED]) wrote:

[snip]
 
:   * Why can one not have a type declarion in the export
: list of a module? Common practice for many people
: is to put these types in comments now (which is really
: dangerous, since the types might change but not the
: comments).

I would love to see type signatures in export lists.

It may also allow you to export a function implemented
with a universal type signature for a certain specific type.

> module Foo( same :: Int -> Int -> Bool ) where
> same :: a -> a -> Bool
> same = (==)


Regards,


Marc




Re: Type signatures in instance declarations?

2000-04-10 Thread Marc van Dongen

George Russell ([EMAIL PROTECTED]) wrote:

: Why are these illegal?  I appreciate that they can't give useful information
: to the compiler, which knows the type already from the class, but in my
: opinion they are still useful to the maintainer, because they serve as
: a reminder of the type.
: 

I agree. I posted a similar comment one or two years ago.


Regards,


Marc van Dongen
-- 
 Marc van Dongen, CS Dept | phone:   +353 21 903578
University College Cork, NUIC | Fax: +353 21 903113
  College Road, Cork, Ireland | Email: [EMAIL PROTECTED]




Re: ServiceShow class for messages

2000-03-31 Thread Marc van Dongen

S.D.Mechveliani ([EMAIL PROTECTED]) wrote:

[ error messages printing their aguments ]

Printing the argument of a function as part of an error
message may lead to infinite error messages. It may even
lead to several calls to error which all have to be shown.
I don't think a compiler will ever be able to detect such infinite
situations and should therefore not be allowed to automatically
print arguments because the quality of the messages will be
very bad.

Also I just looked up the following in the language definition:

  A call to error terminates execution of the program
  and returns an appropriate error indication to the
  operating system. It should also display the string in
  some system-dependent manner. When undefined is used,
  the error message is created by the compiler.

This suggests that a call to error should result in termination.

Perhaps I am missing something.

Regards,


Marc




Re: Ratio: (-1:%1) < (-1:%1)?

2000-03-24 Thread Marc van Dongen

Lennart Augustsson ([EMAIL PROTECTED]) wrote:

: > The definition
: > of (*) in the Prelude has to be clumsy because it cannot
: > assume that this will the case because users can construct
: > their own Ratios.
: How can a user create his own Ratio?  The % operation does the
: GCD reduction, as does every other operation that creates a Ratio.

It is not possible.

As I replied before but you may not have received
it yet, I was wrong in assuming that one could use :%.

Again, sorry about the confusion.

Regards,

Marc van Dongen




Re: Ratio: (-1:%1) < (-1:%1)?

2000-03-24 Thread Marc van Dongen

D. Tweed ([EMAIL PROTECTED]) wrote:

: If you haven't loaded any modules then hugs is in `module scope' of
: prelude and it's possible. If you do, eg, :l List then you end up in that
: module scope and it's no longer allowed.

That's exactly what happend. I ran hugs and typed in (1:?2).
I was just trying to find out why a module with :%'s in it
was not accepted by hugs. Thanks for the explanation.


Regards,

Marc




Re: Ratio: (-1:%1) < (-1:%1)?

2000-03-24 Thread Marc van Dongen

Lennart Augustsson ([EMAIL PROTECTED]) wrote:

: > I am not quite sure how to express this in Haskell
: > terms but here it goes anyway: Why is :% in Ratio
: > not hidden? 
: What?!?  Of course :% is hidden.  It's always been hidden.
: If it isn't it's a bug in your implementation or a (new) bug
: in the repotr.  It's always been hidden before; exposing it would
: be a grave error.

Hmm. I must have missed something. My hugs (1.4) allows it.
I was assuming that Haskell did allow it.
As it turns out my latest ghc doesn't. That's cool.

Thanks.

Sorry for the confusion.

Regards,

Marc




Re: Ratio: (-1:%1) < (-1:%1)?

2000-03-24 Thread Marc van Dongen

Jerzy Karczmarczuk ([EMAIL PROTECTED]) wrote:

[...]
: First of all: at least in Hugs (:%) is *not* exported by
: the Prelude.
: 
: So, it is hidden, and a sane, well educated gentleman would
: not procreate a fraction with negative denominator.

That is the point I am trying to make. Not all people are
gentle. Another thing is that gentlemen normally ensure
a gcd of 1 for numerator and denominator. The definition
of (*) in the Prelude has to be clumsy because it cannot
assume that this will the case because users can construct
their own Ratios.

: The form (1:%-1) is an abomination. Perhaps less than (1:%0), 
: but anyway. But how to have a low-level efficiency and a 
: direct access to data structures, and the respect of all 
: mathematic constraints? In principle we could have a polar
: representation of complexes: (r,theta), and somebody really 
: funny could put a negative r inside.

I haven't looked at that. But if it is not the intended way
to use these things at least it should be documented.
 
: And then somebody really sad would cry that (r,theta) is equal
: but not really, to (r,theta+2PI).

But they are equal. However, see my previous point about
documentation.

[...]

Regards,


Marc
-- 
 Marc van Dongen, CS Dept | phone:  +353 21 4903578
University College Cork, NUIC | Fax:+353 21 4903113
  College Road, Cork, Ireland | Email: [EMAIL PROTECTED]




Ratio: (-1:%1) < (-1:%1)?

2000-03-24 Thread Marc van Dongen

Dear group,


Maybe others have mentioned this as well but I can't
recall having seen this anywhere.

I am not quite sure how to express this in Haskell
terms but here it goes anyway: Why is :% in Ratio
not hidden? 

By allowing a user program to construct elements of
the form (a:%b) one can create objects which lead to
inconsistencies if each of the following hold:
  (1)  for all a: not (a < a);
  (2)  for all a, b and c: if a < b and b < c then a < c.
  (3)  for all a: if a <= b and b <= a then a == b

Now Ratio defines (<=) and (<) as
 (x:%y) <= (x':%y')  =  x * y' <= x' * y
 (x:%y) <  (x':%y')  =  x * y' <  x' * y
According to these definitions and using pseudo notation
the following must hold:
 (-1:%1) < (0:%1) < (1:%-1) == (-1:%1),
The last equality follows from (3) and the fact that:
 (1:%-1) <= (-1:%1) and (-1:%1) <= (1:%-1).
Using (2) it now follows that (-1:%1) < (-1:%1) which
according to (1) should not be true.

According to the language definition (1:%-1) != (-1:%1).
Personally I think that built-in data types should obey
(1), (2) and (3). Maybe I am missing something.

Any comments?


Regards,


Marc van Dongen
-- 
 Marc van Dongen, CS Dept | phone:  +353 21 4903578
University College Cork, NUIC | Fax:+353 21 4903113
  College Road, Cork, Ireland | Email: [EMAIL PROTECTED]




Re: Q: Library for (efficient:-) join and projection

2000-03-13 Thread Marc van Dongen

Hi Tom,

: Hi Marc.
: 
: The Haskell type system can't express a polymorphic natural join.

I can understand that.

: Even the Trex extension to Hugs doesn't quite manage it.  That's why
: I'm keen on a further extension: symmetric record catenation.  :-)

What I need (and I hacked a quick and dirty version)
is something with the following functionality:

data Table variable value = Table [variable] [[value]]

naturalJoin :: (Ord a,Ord b) =>
  Table a b -> Table a b -> Table a b
projection :: (Ord a,Ord b) =>
  Table a b -> [a] -> Table a b

: Also, the attached message may be relevant.

Thanks!

[...]

Regards,


Marc van Dongen



Q: Library for (efficient:-) join and projection

2000-03-12 Thread Marc van Dongen

Dear group,


I don't want to reinvent this wheel and was wondering
if anybody knows of a publicly available library with
functions allowing for the creation of tables, the
computation of natural joins and projections of these
tables (and possibly more).

Any pointer will be greatly appreciated.


Regards,

Marc van Dongen
-- 
 Marc van Dongen, CS Dept | phone:  +353 21 4903578
University College Cork, NUIC | Fax:+353 21 4903113
  College Road, Cork, Ireland | Email: [EMAIL PROTECTED]



Re: Enum instance for Ratio

2000-03-09 Thread Marc van Dongen

George Russell ([EMAIL PROTECTED]) wrote:

: Marc van Dongen wrote:
: > I think it has to respect the implicit order which
: > is defined by toEnum and fromEnum. But I may be wrong.

: Well that's the current definition.  But if you have toEnum and fromEnum
: that's much stronger than Ord.  I don't like toEnum/fromEnum anyway; it makes

Neither do I.

: no sense for Doubles.

I don't like those either:-)

Regards,


Marc



Re: Enum instance for Ratio

2000-03-09 Thread Marc van Dongen

George Russell ([EMAIL PROTECTED]) wrote:

: > data Human = Woman | Man
: Hmm maybe.  But then are you going to make succ Woman = Man or succ Man = Woman??

I think it has to respect the implicit order which
is defined by toEnum and fromEnum. But I may be wrong.

: It seems to me that in any case you are going to upset people.

By defining successor or predecessor?

: Humans are a special case because there are only two ways of ordering the
: sexes, and both are controversial.  If we have
:data Colour = Red | Blue | Yellow
: and want to make Colour an instance of Enum, then to consistently define [..]
: you need to make arbitrary choices.  If you're going to arbitrarily choose an
: enumeration it doesn't seem unreasonable to me to arbitrarily choose an ordering
: as well.

I have to think about that.

Regards,


Marc



Re: More on randoms

2000-02-04 Thread Marc van Dongen


Jerzy Karczmarczuk ([EMAIL PROTECTED]) wrote:

[...]

: the Haskell standard libraries offer only the basic integer RNG,
: which will force all the users to reconstruct the needed reals,
: this is not extremely painful, but anyway.
: I would love having 'next' returning reals as well...
: And vectors (with decently uncorrelated elements). Etc.

Yes please. But do change the word vector into [Integer].


[...]
 
Regards,


Marc van Dongen



How much MB do I need

1996-02-26 Thread Marc van Dongen


To compile a large Haskell program. I am compiling at the moment
without optimization and 55 MB of heap. Still ghc complains that
the heap is too small.

Any suggestions?


Marc van Dongen
[EMAIL PROTECTED]






happy related question

1996-02-24 Thread Marc van Dongen


Dear all,


Could someone explain me why the following does not work?
Any help is *greatly* appreciated. If I can't find out
what causes this problem, I'll have to program in c and
use yacc & lex for the next 2.5 years :-(


Sincerely,


Marc van Dongen
[EMAIL PROTECTED]

*** tmp.ly **

> {
> module Tmp(happyError) where
> }

> %name test
> %tokentype { Token }
> %token
>  var { TokVar }
> %newline { '\n' }
> %%

> Test :: { String }
> Test:{ "" }

  Test: var{ "" } -- also won't work

> {

> happyError :: Int -> [Token] -> a
> happyError i _ = error ("Parse error in line " ++ show i ++ "\n")

> data Token = TokVar

> }

*** happying and ghcing *
> happy tmp.ly
> ghc -c tmp.hs
 
"tmp.hs", line 41:
Couldn't match the type `Token' against `Char'.
Inside two case alternatives:
... TokVar -> cont 2
... '\n' -> happyNewToken action (ln + 1) tks
 
Compilation had errors
* tmp.hs 

-- parser produced by Happy Version 0.8


module Tmp(happyError) where

data HappyAbsSyn 
= HappyTerminal ( Token )
| HappyAbsSyn1 (  String  )

type HappyReduction = 
   Int 
-> ( Token ) 
-> HappyState ( Token ) ([HappyAbsSyn] -> ( String )) 
-> Int 
-> [ Token ] 
-> [HappyState ( Token ) ([HappyAbsSyn] -> ( String ))] 
-> [HappyAbsSyn] 
-> ( String )

action_0,
 action_1 :: Int -> HappyReduction

happyReduce_1 :: HappyReduction

action_0 1 = happyGoto action_1
action_0 _ = happyReduce_1

action_1 3 = happyAccept
action_1 _ = happyFail

happyReduce_1 = specHappyReduce_0 1 reduction where {
  reduction (
happyRest)
happy_var_lineno = HappyAbsSyn1
(  ""  ) : happyRest}

happyNewToken action ln []
= action 3 3 (error "reading EOF!") (HappyState action) ln []

happyNewToken action ln (tk:tks) = case tk of
 TokVar  -> cont 2
 '\n'  -> happyNewToken action (ln + 1) tks
  where cont i = action i i tk (HappyState action) ln tks

test = happyParse



happyError :: Int -> [Token] -> a
happyError i _ = error ("Parse error in line " ++ show i ++ "\n")

data Token = TokVar

-- Start of Happy Template (version 0.8)

happyParse tks = happyNewToken action_0 (1::Int) tks [] []

-- All this HappyState stuff is simply because we can't have recursive
-- types in Haskell without an intervening data structure.

data HappyState b c = HappyState
(Int -> -- token number
 Int -> -- token number (yes, again)
 b ->   -- token semantic value
 HappyState b c ->  -- current state
 Int -> -- line number
 [b] -> -- rest of tokens
 [HappyState b c] ->-- state stack
 c)

-- Ok, Here are the action functions.

happyAccept _ _ _ _ _ _ [ HappyAbsSyn1 ans ] = ans

happyFail   _ _ _ ln tks _ _ = happyError ln tks

happyShift new_state i tk st ln tks sts stk =
 happyNewToken new_state ln tks (st:sts) (HappyTerminal tk:stk)

happyGoto action j tk st = action j j tk (HappyState action)

-- happyReduce is specialised for the common cases.

specHappyReduce_0 i fn j tk st@(HappyState action) ln tks sts stk
 = action i j tk st ln tks (st:sts) (fn stk ln)
specHappyReduce_1 i fn j tk _ ln tks sts@(st@(HappyState action):_) stk
 = action i j tk st ln tks sts (fn stk ln)
specHappyReduce_2 i fn j tk _ ln tks (_:sts@(st@(HappyState action):_)) stk
 = action i j tk st ln tks sts (fn stk ln)
specHappyReduce_3 i fn j tk _ ln tks (_:_:sts@(st@(HappyState action):_)) stk
 = action i j tk st ln tks sts (fn stk ln)

happyReduce i k fn j tk st ln tks sts stk
  = action i j tk st' ln tks sts' (fn stk ln)
   where sts'@(st'@(HappyState action):_) = drop (k::Int) (st:sts)

-- Internal happy errors:

notHappyAtAll :: Int -> a
notHappyAtAll i = error ("Internal Happy error in reduction ( " 
   ++ show i ++ " )")

-- end of Happy Template.