Re: [Haskell-cafe] What is a number. (Was: Num instances for 2-dimensional types)

2009-10-06 Thread Jason Dagit
On Mon, Oct 5, 2009 at 11:02 AM, Sönke Hahn sh...@cs.tu-berlin.de wrote:

 
  On 5 Oct 2009, at 21:06, Lennart Augustsson wrote:
   OK, just pairs have no arithmetic, but one way of defining
   arithmetic is to treat the pairs as complex numbers.  Or as mantissa
   and exponent.  Or as something else.  So there's nothing wrong, IMO,
   to make pairs an instance of Num if you so desire.  (Though I'd
   probably introduce a new type.)

 I was looking for one intuitive way of instantiating pairs of numbers as
 Num.
 One where i wouldn't have to look in the documentation to remember what (+)
 does. So considering all these examples of what pairs of numbers could be,
 i
 agree with Miguel Mitrofanov: It's something that should not be done.

 Two questions remain, i think:

 1. How can i have some notion of addition and subtraction for something
 that i
 don't want to put in the Num class?

 That's easy: I could just write a class that defines binary operators (like
 (+~) and (-~), for example). I don't get  the fanciness of (+), but that's
 okay.


I don't know how well it works in practice, but you could hide the prelude
in your module and then import it qualified.  This would allow your module
to redefine the normal symbols as the operators you want them to be.



 2. How can i use numeric literals to construct values, whose types are not
 in
 the Num class?


This I don't know how to do without a pre-processor or maybe Template
Haskell would work.



 Haskell could provide a class IsNumber (like IsString for string literals).
 Is
 that something we would want?


Seems like IsBoolean would also be useful if you went this route.  And
perhaps, IsList :)  I'm sure we could think of more.  I can see how they
would be handy for anyone making an eDSL, especially if combine with view
patterns.

Jason
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] What is a number. (Was: Num instances for 2-dimensional types)

2009-10-06 Thread Henning Thielemann


On Mon, 5 Oct 2009, Jason Dagit wrote:


2. How can i use numeric literals to construct values, whose types are not
in
the Num class?


Numeric literals are treated as Integer or Rational, and are then 
converted with the function fromInteger or fromRational, respectively, to 
the required type. Whatever fromInteger function is in scope, will be 
used. If fromInteger is in a class other than Num (in NumericPrelude it is 
Ring, but it can be also a function that is not a class method), then 
number literals have a type like:

  2 :: MyNumClass a = a

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] What is a number. (Was: Num instances for 2-dimensional types)

2009-10-06 Thread Iavor Diatchki
Hi,

On Tue, Oct 6, 2009 at 2:37 AM, Henning Thielemann
lemm...@henning-thielemann.de wrote:
 Numeric literals are treated as Integer or Rational, and are then converted
 with the function fromInteger or fromRational, respectively, to the required
 type. Whatever fromInteger function is in scope, will be used. If
 fromInteger is in a class other than Num (in NumericPrelude it is Ring, but
 it can be also a function that is not a class method), then number literals
 have a type like:
  2 :: MyNumClass a = a

This is only the case if you use GHC's NoImplicitPrelude extension,
otherwise the fromInteger of the Prelude is used, even if it is not
in scope.  Here is an example:

module A where

  boolLit :: Integer - Bool
  boolLit 0 = False
  boolLit _ = True


{-# LANGUAGE NoImplicitPrelude #-}
module Main where

  import A(boolLit)
  import Prelude(Integer,Bool,print)

  fromInteger :: Integer - Bool
  fromInteger = boolLit

  main = print 0


Note that 0 means different things in the different modules!

-Iavor
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] What is a number. (Was: Num instances for 2-dimensional types)

2009-10-05 Thread Anton van Straaten

jerzy.karczmarc...@info.unicaen.fr wrote:

American people will call it a discussion about semantics, and
we, European will not understand why this word is used in a pejorative
context...


Semantics *should* be a pejorative word unless it refers to something 
formally specified, and preferably executable or machine-checkable. 
Those subtle Contintental critics of informal semantics, namely Derrida, 
Irigaray, et al, showed us why.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] What is a number. (Was: Num instances for 2-dimensional types)

2009-10-05 Thread Miguel Mitrofanov

Just pairs have no natural arithmetic upon them.


Exactly my point.


BTW. the missing term of M.M. is DUAL NUMBERS.


Remembered this already. Thanks anyway.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] What is a number. (Was: Num instances for 2-dimensional types)

2009-10-05 Thread Lennart Augustsson
OK, just pairs have no arithmetic, but one way of defining
arithmetic is to treat the pairs as complex numbers.  Or as mantissa
and exponent.  Or as something else.  So there's nothing wrong, IMO,
to make pairs an instance of Num if you so desire.  (Though I'd
probably introduce a new type.)

On Mon, Oct 5, 2009 at 6:46 PM, Miguel Mitrofanov miguelim...@yandex.ru wrote:
 Just pairs have no natural arithmetic upon them.

 Exactly my point.

 BTW. the missing term of M.M. is DUAL NUMBERS.

 Remembered this already. Thanks anyway.

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] What is a number. (Was: Num instances for 2-dimensional types)

2009-10-05 Thread Miguel Mitrofanov

And I agree that sometimes it can be suitable.

But simply defining an instance of Num without a single word on the  
problem one
is trying to solve is not just pointless. It's something that should  
not be done.


On 5 Oct 2009, at 21:06, Lennart Augustsson wrote:


OK, just pairs have no arithmetic, but one way of defining
arithmetic is to treat the pairs as complex numbers.  Or as mantissa
and exponent.  Or as something else.  So there's nothing wrong, IMO,
to make pairs an instance of Num if you so desire.  (Though I'd
probably introduce a new type.)

On Mon, Oct 5, 2009 at 6:46 PM, Miguel Mitrofanov miguelim...@yandex.ru 
 wrote:

Just pairs have no natural arithmetic upon them.


Exactly my point.


BTW. the missing term of M.M. is DUAL NUMBERS.


Remembered this already. Thanks anyway.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] What is a number. (Was: Num instances for 2-dimensional types)

2009-10-05 Thread Sönke Hahn
 
 On 5 Oct 2009, at 21:06, Lennart Augustsson wrote:
  OK, just pairs have no arithmetic, but one way of defining
  arithmetic is to treat the pairs as complex numbers.  Or as mantissa
  and exponent.  Or as something else.  So there's nothing wrong, IMO,
  to make pairs an instance of Num if you so desire.  (Though I'd
  probably introduce a new type.)

I was looking for one intuitive way of instantiating pairs of numbers as Num. 
One where i wouldn't have to look in the documentation to remember what (+) 
does. So considering all these examples of what pairs of numbers could be, i 
agree with Miguel Mitrofanov: It's something that should not be done.

Two questions remain, i think:

1. How can i have some notion of addition and subtraction for something that i 
don't want to put in the Num class?

That's easy: I could just write a class that defines binary operators (like 
(+~) and (-~), for example). I don't get  the fanciness of (+), but that's 
okay.

2. How can i use numeric literals to construct values, whose types are not in 
the Num class?

Haskell could provide a class IsNumber (like IsString for string literals). Is 
that something we would want?

BTW, interesting discussion, thanks!

Sönke


On Monday 05 October 2009 07:24:37 pm Miguel Mitrofanov wrote:
 And I agree that sometimes it can be suitable.
 
 But simply defining an instance of Num without a single word on the
 problem one
 is trying to solve is not just pointless. It's something that should
 not be done.
 
  On Mon, Oct 5, 2009 at 6:46 PM, Miguel Mitrofanov miguelim...@yandex.ru
 
   wrote:
  
  Just pairs have no natural arithmetic upon them.
 
  Exactly my point.
 
  BTW. the missing term of M.M. is DUAL NUMBERS.
 
  Remembered this already. Thanks anyway.
 
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe
 
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe