On 3 February 2011 02:35, Brandon Moore brandon_m_mo...@yahoo.com wrote:
Here's one thing to consider:
Can you write a function
f :: (Data a) = a - String
f x = termTag x
It would seem the Data a = Term a instance justifies
this function, and it will always use the default instance.
OK, what about this as a use case then. I want to create a type class 'Term'
with only one function in it. The function returns a 'termTag' which labels
the
kind of a value in a DSL.
class Term a where
termTag :: a - String
A user of this type-class can happily provide an instance
From: Steffen Schuldenzucker sschuldenzuc...@uni-bonn.de
On 01/31/2011 08:58 PM, MattMan wrote:
[...]
data Wrapper a = Wrap a
instance (Num a) = AbGroup (Wrapper a) where
add (Wrap i) (Wrap j) = Wrap(i+j)
However, this is clumsy. Is there something else I can do? Thanks
On 1 February 2011 11:41, John Lato jwl...@gmail.com wrote:
The important point is that this declares an AbGroup instance for every
type, not just types with Num instances.
So, is there a way to declare an AbGroup instance for the types with num
instances only?
Thanks,
Ozgur
On 1 February 2011 11:47, Ozgur Akgun ozgurak...@gmail.com wrote:
So, is there a way to declare an AbGroup instance for the types with num
instances only?
No - as Henning says its then no more useful than simply a function:
add :: (Num u) = a - a - a
add = (+)
'Overarching instances' i.e.
OK, what about this as a use case then. I want to create a type class 'Term'
with only one function in it. The function returns a 'termTag' which labels
the *kind* of a value in a DSL.
class Term a where
termTag :: a - String
A user of this type-class can happily provide an instance without
On Tue, Feb 1, 2011 at 11:47 AM, Ozgur Akgun ozgurak...@gmail.com wrote:
On 1 February 2011 11:41, John Lato jwl...@gmail.com wrote:
The important point is that this declares an AbGroup instance for every
type, not just types with Num instances.
So, is there a way to declare an AbGroup
On Tuesday 01 February 2011 13:45:34, Ozgur Akgun wrote:
I want to be able to write the following instance to accomplish that:
instance Data t = Term t where
termTag = show . toConstr
And if the user wants to write a more specific instance, they should be
welcome to do so:
instance
On 1 February 2011 12:45, Ozgur Akgun ozgurak...@gmail.com wrote:
I am not very much interested in the technical details about how things
currently are, I am more interested in a discussion about why (if?) this
would be considered a design flaw?
Wanting a general base case + specific
tldr: Can I make arbitrary instances of one class instantiate another without
using wrappers?
I'm new to Haskell, and am trying to implement some simple typeclasses for
doing algebra. For example I have type class (simplified for the sake of
argument)
class AbGroup a where
add :: a - a - a
On 01/31/2011 08:58 PM, MattMan wrote:
[...]
data Wrapper a = Wrap a
instance (Num a) = AbGroup (Wrapper a) where
add (Wrap i) (Wrap j) = Wrap(i+j)
However, this is clumsy. Is there something else I can do? Thanks
This is the normal approach. You can do funny things with the
On Monday 31 January 2011 20:58:02, MattMan wrote:
tldr: Can I make arbitrary instances of one class instantiate another
without using wrappers?
I'm new to Haskell, and am trying to implement some simple typeclasses
for doing algebra. For example I have type class (simplified for the
sake
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
On 1/31/11 15:24 , Daniel Fischer wrote:
want. You could then also enable OverlappingInstances, which would allow
you to write other instances, but that extension is widely regarded as
dangerous (have to confess, I forgot what the dangers were,
On Mon, 31 Jan 2011, MattMan wrote:
I'm new to Haskell, and am trying to implement some simple typeclasses for
doing algebra. For example I have type class (simplified for the sake of
argument)
class AbGroup a where
add :: a - a - a
I would like any type instantiating Num to also be an
On Mon, 31 Jan 2011, Brandon S Allbery KF8NH wrote:
On 1/31/11 15:24 , Daniel Fischer wrote:
want. You could then also enable OverlappingInstances, which would allow
you to write other instances, but that extension is widely regarded as
dangerous (have to confess, I forgot what the dangers
\quote
Henning Thielemann wrote:
If all methods of AbGroup can be defined for all Num types - why do you
want an AbGroup at all? You could simply write functions with Num
constraint.
Well, I'd rather not have to implement (*), abs, etc on every abelian group.
You may be also
16 matches
Mail list logo