Re: [Haskell-cafe] Overloading

2013-03-12 Thread Miguel Mitrofanov
12.03.2013, 02:53, Richard A. O'Keefe o...@cs.otago.ac.nz: On 12/03/2013, at 10:00 AM, MigMit wrote:  On Mar 12, 2013, at 12:44 AM, Richard A. O'Keefe o...@cs.otago.ac.nz wrote:  Prelude :type (+)  (+) :: Num a = a - a - a  The predefined (+) in Haskell requires its arguments and its

Re: [Haskell-cafe] Overloading

2013-03-12 Thread Carlos Camarao
On 12/03/2013, at 3:15 AM, Carlos Camarao wrote: Hi, I just started playing around a bit with Haskell, so sorry in advance for very basic (and maybe stupid) questions. Coming from the C++ world one thing I would like to do is overloading operators. For example I want to

Re: [Haskell-cafe] Overloading

2013-03-12 Thread Brandon Allbery
On Tue, Mar 12, 2013 at 1:52 PM, Carlos Camarao carlos.cama...@gmail.comwrote: Sorry, I think my sentence: To define (+) as an overloaded operator in Haskell, you have to define and use a type class. is not quite correct. I meant that to define any operator in Haskell you have to

Re: [Haskell-cafe] Overloading

2013-03-12 Thread Carlos Camarao
On Tue, Mar 12, 2013 at 3:21 PM, Brandon Allbery allber...@gmail.comwrote: On Tue, Mar 12, 2013 at 1:52 PM, Carlos Camarao carlos.cama...@gmail.comwrote: Sorry, I think my sentence: To define (+) as an overloaded operator in Haskell, you have to define and use a type class. is

Re: [Haskell-cafe] Overloading

2013-03-12 Thread Richard A. O'Keefe
Carlos Camarao wrote: Sorry, I think my sentence: To define (+) as an overloaded operator in Haskell, you have to define and use a type class. is not quite correct. I meant that to define any operator in Haskell you have to have a type class defined with that operator as member.

Re: [Haskell-cafe] Overloading

2013-03-12 Thread MigMit
On Mar 13, 2013, at 12:54 AM, Richard A. O'Keefe o...@cs.otago.ac.nz wrote: The interesting challenge here is that we should have Date + Period - Date Date - Period - Date Period + Date - Date Period - Date - ILLEGAL Period + Period - DeriodPeriod - Period -

Re: [Haskell-cafe] Overloading

2013-03-12 Thread David Thomas
If you add NoImplicitPrelude, I think you should also be able to do: import Prelude hiding (Num) import qualified Prelude (Num) instance Num a = Plus a a where type PlusResult a a = a a + b = a Prelude.+ b On Tue, Mar 12, 2013 at 2:24 PM, MigMit miguelim...@yandex.ru wrote: On Mar

Re: [Haskell-cafe] Overloading

2013-03-12 Thread Donn Cave
On Mar 13, 2013, at 12:54 AM, Richard A. O'Keefe o...@cs.otago.ac.nz wrote: The interesting challenge here is that we should have Date + Period - Date Date - Period - Date Period + Date - Date Period - Date - ILLEGAL Period + Period - DeriodPeriod - Period -

Re: [Haskell-cafe] Overloading

2013-03-12 Thread Carlos Camarao
On Tue, Mar 12, 2013 at 5:54 PM, Richard A. O'Keefe o...@cs.otago.ac.nz wrote: Carlos Camarao wrote: Sorry, I think my sentence: To define (+) as an overloaded operator in Haskell, you have to define and use a type class. is not quite correct. I meant that

Re: [Haskell-cafe] Overloading

2013-03-11 Thread Carlos Camarao
On Sat, Mar 9, 2013 at 5:33 PM, Peter Caspers pcaspers1...@gmail.com wrote: Hi, I just started playing around a bit with Haskell, so sorry in advance for very basic (and maybe stupid) questions. Coming from the C++ world one thing I would like to do is overloading operators.

Re: [Haskell-cafe] Overloading

2013-03-11 Thread Richard A. O'Keefe
On 12/03/2013, at 3:15 AM, Carlos Camarao wrote: On Sat, Mar 9, 2013 at 5:33 PM, Peter Caspers pcaspers1...@gmail.com wrote: Hi, I just started playing around a bit with Haskell, so sorry in advance for very basic (and maybe stupid) questions. Coming from the C++ world

Re: [Haskell-cafe] Overloading

2013-03-11 Thread MigMit
On Mar 12, 2013, at 12:44 AM, Richard A. O'Keefe o...@cs.otago.ac.nz wrote: Prelude :type (+) (+) :: Num a = a - a - a The predefined (+) in Haskell requires its arguments and its result to be precisely the same type. I think you had better justify the claim that Date+Period - Date and

Re: [Haskell-cafe] Overloading

2013-03-11 Thread Richard A. O'Keefe
On 12/03/2013, at 10:00 AM, MigMit wrote: On Mar 12, 2013, at 12:44 AM, Richard A. O'Keefe o...@cs.otago.ac.nz wrote: Prelude :type (+) (+) :: Num a = a - a - a The predefined (+) in Haskell requires its arguments and its result to be precisely the same type. I think you had

Re: [Haskell-cafe] Overloading

2013-03-10 Thread MigMit
On Mar 10, 2013, at 11:47 AM, Peter Caspers pcaspers1...@gmail.com wrote: Thank you all for your answers, this helps a lot. To clarify my last point ... Also again, taking this way I can not provide several constructors taking inputs of different types, can I ? Sorry, didn't get what you

Re: [Haskell-cafe] Overloading

2013-03-10 Thread ok
In C++ it is perfectly normal to have overloaded functions like f : Int - Int - Int f : Int - Char - Int Something that may not be obvious about Haskell is that Haskell does NOT have overloaded functions/operators at all. More precisely, for any identifier and any point in a Haskell

Re: [Haskell-cafe] Overloading

2013-03-10 Thread Peter Caspers
In C++ it is perfectly normal to have overloaded functions like f : Int - Int - Int f : Int - Char - Int Something that may not be obvious about Haskell is that Haskell does NOT have overloaded functions/operators at all. thanks, this was the core of my question. So by example, if I define

Re: [Haskell-cafe] Overloading

2013-03-10 Thread Daniel Trstenjak
Hi Peter, -- smart constructor with serialNumber date serialNumber | serialNumber 0 = Date serialNumber | otherwise = error (invalid serialNumber ++ show serialNumber) Instead of raising an error it's more secure to return a Maybe value. date :: Int - Maybe Date date

Re: [Haskell-cafe] Overloading

2013-03-10 Thread Peter Caspers
Hi Daniel, Instead of raising an error it's more secure to return a Maybe value. date :: Int - Maybe Date date serialNumber | serialNumber 0 = Just $ Date serialNumber | otherwise= Nothing yes, I understand (Maybe seems the equivalent of c++'s boost::optionalT). -- smart

Re: [Haskell-cafe] Overloading

2013-03-10 Thread Donn Cave
Peter Caspers pcaspers1...@gmail.com, data Month = January | ... ok, I will try to change my code in that direction. The idea is clear. To whatever extent these algebraic data types do map to integer values for your purposes, you can implement that by making Month an instance of Enum.

Re: [Haskell-cafe] Overloading

2013-03-10 Thread Richard A. O'Keefe
On 11/03/2013, at 12:10 AM, Peter Caspers wrote: thanks, this was the core of my question. So by example, if I define a Date type as data Date = Date Int deriving Show representing a date by its serial number and want two constructors (conditions are only examples here) -- smart

[Haskell-cafe] Overloading

2013-03-09 Thread Peter Caspers
Hi, I just started playing around a bit with Haskell, so sorry in advance for very basic (and maybe stupid) questions. Coming from the C++ world one thing I would like to do is overloading operators. For example I want to write (Date 6 6 1973) + (Period 2 Months) for some self defined types

Re: [Haskell-cafe] Overloading

2013-03-09 Thread MigMit
On Mar 10, 2013, at 12:33 AM, Peter Caspers pcaspers1...@gmail.com wrote: Hi, I just started playing around a bit with Haskell, so sorry in advance for very basic (and maybe stupid) questions. Coming from the C++ world one thing I would like to do is overloading operators. For example I

Re: [Haskell-cafe] Overloading

2013-03-09 Thread Anthony Cowley
On Mar 9, 2013, at 3:33 PM, Peter Caspers pcaspers1...@gmail.com wrote: Hi, I just started playing around a bit with Haskell, so sorry in advance for very basic (and maybe stupid) questions. Coming from the C++ world one thing I would like to do is overloading operators. For example I

Re: [Haskell-cafe] Overloading

2013-03-09 Thread Amy de Buitléir
Also again, taking this way I can not provide several constructors taking inputs of different types, can I ? You can have multiple constructors, taking different numbers and types of input parameters, yes. ___ Haskell-Cafe mailing list

Re: [Haskell-cafe] Overloading

2013-03-09 Thread Peter Caspers
Thank you all for your answers, this helps a lot. To clarify my last point ... Also again, taking this way I can not provide several constructors taking inputs of different types, can I ? Sorry, didn't get what you mean here. In C++ it is perfectly normal to have overloaded functions like

[Haskell-cafe] overloading integer literals

2012-08-14 Thread Евгений Пермяков
During development some toy base library I found impossible to use Numeric literals. Quick search showed, that one need both fromInteger in scope (reasonable) and, as I understand, access to Integer type from 'base' package ('base' for clarity later). It is perfectly reasonable if we assume

[Haskell-cafe] overloading

2012-07-12 Thread Patrick Browne
Hi,I am comparing Haskell's class/instance techniques for overloading with those available Order Sorted Algebra (OSA in CafeOBJ) Using just the basic class/instance mechanism is there any way to avoid the type annotations in the evaluations below?Patclass Location a b where move::a-binstance

[Haskell-cafe] Overloading in a sub-class

2011-08-17 Thread Patrick Browne
Hi, Below are two questions concerning overloading in a sub-class. Thanks, Pat class Numb0 a where (+) :: a - a - a negate :: a - a instance Numb0 Int where x + y = y negate x = x -- Are + and negate part of the signature of Numb1? class Numb0 a = Numb1 a where -- Is it possible to

Re: [Haskell-cafe] Overloading in a sub-class

2011-08-17 Thread Albert Y. C. Lai
On 11-08-17 12:10 PM, Patrick Browne wrote: -- Are + and negate part of the signature of Numb1? class Numb0 a = Numb1 a where No. -- Is it possible to override these operations in instances of Numb1? -- Something like: -- instance Numb1 Float where --x + y = y --negate x = x

Re: [Haskell-cafe] overloading show function

2011-06-30 Thread Holger Siegel
Am 29.06.2011 um 23:50 schrieb Philipp Schneider: Hi cafe, in my program i use a monad of the following type newtype M a = M (State - (a, State)) i use the monad in two different ways. The type variable a can be a pair as in interp :: Term - Environment - M (Value,Environment)

Re: [Haskell-cafe] overloading show function

2011-06-30 Thread Wolfgang Braun
An environment contains local variable bindings, so no subcomputation will ever need to return its environment. - That is not true. A subcomputation can possible modify an environment except the language forbids such a case. On 06/30/2011 02:36 PM, Holger Siegel wrote: Am 29.06.2011 um

Re: [Haskell-cafe] overloading show function

2011-06-30 Thread Philipp Schneider
On 06/30/2011 02:36 PM, Holger Siegel wrote: Am 29.06.2011 um 23:50 schrieb Philipp Schneider: Hi cafe, in my program i use a monad of the following type newtype M a = M (State - (a, State)) i use the monad in two different ways. The type variable a can be a pair as in interp :: Term -

Re: [Haskell-cafe] overloading show function

2011-06-30 Thread Philipp Schneider
On 06/30/2011 08:25 PM, Philipp Schneider wrote: On 06/30/2011 02:36 PM, Holger Siegel wrote: Am 29.06.2011 um 23:50 schrieb Philipp Schneider: Hi cafe, in my program i use a monad of the following type newtype M a = M (State - (a, State)) i use the monad in two different ways. The type

Re: [Haskell-cafe] overloading show function

2011-06-30 Thread Holger Siegel
Am 30.06.2011 um 20:23 schrieb Philipp Schneider: On 06/30/2011 02:36 PM, Holger Siegel wrote: Am 29.06.2011 um 23:50 schrieb Philipp Schneider: Hi cafe, in my program i use a monad of the following type newtype M a = M (State - (a, State)) i use the monad in two different ways.

Re: [Haskell-cafe] overloading show function

2011-06-30 Thread Philipp Schneider
On 06/30/2011 09:49 PM, Holger Siegel wrote: Am 30.06.2011 um 20:23 schrieb Philipp Schneider: On 06/30/2011 02:36 PM, Holger Siegel wrote: Am 29.06.2011 um 23:50 schrieb Philipp Schneider: Hi cafe, in my program i use a monad of the following type newtype M a = M (State - (a, State))

Re: [Haskell-cafe] overloading show function

2011-06-30 Thread Holger Siegel
Am 30.06.2011 um 22:57 schrieb Philipp Schneider: On 06/30/2011 09:49 PM, Holger Siegel wrote: (...) But that won't work: After you have evaluated an entry of the environment, you store the resulting value but you throw away its updated environment. That means, you lose the results of all

Re: [Haskell-cafe] overloading show function

2011-06-30 Thread Philipp Schneider
On 06/30/2011 11:46 PM, Holger Siegel wrote: Am 30.06.2011 um 22:57 schrieb Philipp Schneider: On 06/30/2011 09:49 PM, Holger Siegel wrote: (...) But that won't work: After you have evaluated an entry of the environment, you store the resulting value but you throw away its updated

[Haskell-cafe] overloading show function

2011-06-29 Thread Philipp Schneider
Hi cafe, in my program i use a monad of the following type newtype M a = M (State - (a, State)) i use the monad in two different ways. The type variable a can be a pair as in interp :: Term - Environment - M (Value,Environment) and it can be just a value as in type Environment = [(Name,

Re: [Haskell-cafe] overloading show function

2011-06-29 Thread aditya siram
Try enabling OverlappingInstances extension by adding this to the top of the file: {-# LANGUAGE OverlappingInstances #-} -deech On Wed, Jun 29, 2011 at 4:50 PM, Philipp Schneider philipp.schneid...@gmx.net wrote: Hi cafe, in my program i use a monad of the following type newtype M a = M

Re: [Haskell-cafe] overloading show function

2011-06-29 Thread Steffen Schuldenzucker
Hi Philipp, On 06/29/2011 11:50 PM, Philipp Schneider wrote: Hi cafe, in my program i use a monad of the following type newtype M a = M (State - (a, State)) btw., it looks like you just rebuilt the State monad. ... instance (Show a,Show b) = Show (M (a,b)) where show (M f) = let

Re: [Haskell-cafe] overloading show function

2011-06-29 Thread Philipp Schneider
Thank you very much, this worked. On 06/30/2011 12:03 AM, aditya siram wrote: Try enabling OverlappingInstances extension by adding this to the top of the file: {-# LANGUAGE OverlappingInstances #-} -deech On Wed, Jun 29, 2011 at 4:50 PM, Philipp Schneider philipp.schneid...@gmx.net

Re: [Haskell-cafe] Overloading functions based on arguments?

2009-02-13 Thread Eugene Kirpichov
class Foobar a b where foobar :: a - b - Int instance Foobar String Int where ... instance Foobar Int String where ... 2009/2/13 Daniel Kraft d...@domob.eu: Hi, I just came across a problem like this: Suppose I've got two related functions that do similar things, and I want to call them

Re: [Haskell-cafe] Overloading functions based on arguments?

2009-02-13 Thread Colin Adams
If you have two functions that do two different things, then they certainly OUGHT to have different names. You can of course put the two functions in different modules. Then they do have different (qualified) names. 2009/2/13 Daniel Kraft d...@domob.eu: Hi, I just came across a problem like

Re: [Haskell-cafe] Overloading functions based on arguments?

2009-02-13 Thread Duncan Coutts
On Fri, 2009-02-13 at 13:25 +0300, Eugene Kirpichov wrote: class Foobar a b where foobar :: a - b - Int instance Foobar String Int where ... instance Foobar Int String where ... But we typically do not to this. It's ugly. Classes work nicely when there is some kind of parametrisation

[Haskell-cafe] Overloading functions based on arguments?

2009-02-13 Thread Daniel Kraft
Hi, I just came across a problem like this: Suppose I've got two related functions that do similar things, and I want to call them the same... Like in: foobar :: String - Int - Int foobar :: Int - String - Int (Bad example, but I hope you got the point.) Is this kind of overloading

Re: [Haskell-cafe] Overloading functions based on arguments?

2009-02-13 Thread Henning Thielemann
Daniel Kraft wrote: Hi, I just came across a problem like this: Suppose I've got two related functions that do similar things, and I want to call them the same... Like in: foobar :: String - Int - Int foobar :: Int - String - Int (Bad example, but I hope you got the point.)