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
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
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
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
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.
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 -
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
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 -
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
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.
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
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
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
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
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
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
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
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
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.
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
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
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
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
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
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
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
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
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
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
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)
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
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 -
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
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.
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))
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
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
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,
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
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
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
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
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
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
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
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.)
46 matches
Mail list logo