On 3 February 2011 02:35, Brandon Moore 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.
>
> Now, what happ
>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
On 1 February 2011 12:45, Ozgur Akgun 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 exceptional cases is in no
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:
>
> in
On Tue, Feb 1, 2011 at 11:47 AM, Ozgur Akgun wrote:
> On 1 February 2011 11:41, John Lato 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 nu
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 1 February 2011 11:47, Ozgur Akgun 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. classes with one
On 1 February 2011 11:41, John Lato 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
__
>
> From: Steffen Schuldenzucker
>
> 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
<\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
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 wer
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
-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 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
> s
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
Overlapp
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 ->
16 matches
Mail list logo