[Haskell-cafe] Type classes

2013-05-28 Thread Johannes Gerer
Dear Haskellers, While trying to understand the interconnection and hierarchy behind the important typeclasses, I stumbled upon the following question that I am not able to answer: There seems to be a hierachy of the type classes, in the sense, that the more powerfull a class is, the more

Re: [Haskell-cafe] Type classes

2013-05-28 Thread Anton Kholomiov
I don't understand the final part of the question but here are some comments for the first part. I don't like the phrase: the more powerfull a class is, the more fleixblility you have for combining them to complex programs powerfull, more flexibility, complex programs -- are not so precise

Re: [Haskell-cafe] Type classes

2013-05-28 Thread Johannes Gerer
Thank you for the comments on the first part. While one can argue about the different meanings of powerful and flexible here, that's not the question. The question is, about showing A = B using wrappers like Kleisli or Cokleisli: I can use Kleisli to show that a Monad can do everything an

Re: [Haskell-cafe] Type classes

2013-05-28 Thread Tom Ellis
On Tue, May 28, 2013 at 04:42:35PM +0200, Johannes Gerer wrote: By the same argument, could'nt I say, that any type class (call it AnyClass) can do everything a Monad can: instance AnyClass m = Monad (Cokleilsi m ()) That doesn't say that AnyClass can do anything a Monad can. AnyClass m =

Re: [Haskell-cafe] Type classes

2013-05-28 Thread Johannes Gerer
That makes sense. But why does instance Monad m = ArrowApply (Kleisli m) show that a Monad can do anything an ArrowApply can (and the two are thus equivalent)? On Tue, May 28, 2013 at 5:17 PM, Tom Ellis tom-lists-haskell-cafe-2...@jaguarpaw.co.uk wrote: On Tue, May 28, 2013 at 04:42:35PM

Re: [Haskell-cafe] Type classes

2013-05-28 Thread Tom Ellis
On Tue, May 28, 2013 at 05:21:58PM +0200, Johannes Gerer wrote: That makes sense. But why does instance Monad m = ArrowApply (Kleisli m) show that a Monad can do anything an ArrowApply can (and the two are thus equivalent)? I've tried to chase around the equivalence between these two

Re: [Haskell-cafe] Type classes

2013-05-28 Thread Johannes Gerer
Ok, now I see a difference, why Kleisli can be used to relate typeclasses (like Monad and ArrowApply) and Cokleisli can not: Kleisli m () _ = () - m _ is isomorphic to m _ whereas Cokleisli m () _ = m _ - () is not. Can somebody point out the relevant category theoretical concepts, that are

Re: [Haskell-cafe] Type classes

2013-05-28 Thread Johannes Gerer
What about these two very simple type classes. Are they equivalent? (As Monad and ArrowApply) (This actually compiles in GHC) class Pointed f where pure :: a - f a class Unit f where unit :: f a a newtype UnitPointed f a = UnitPointed f a a instance Unit f = Pointed (UnitPointed f) where

Re: [Haskell-cafe] Type classes

2013-05-28 Thread Tom Ellis
On Tue, May 28, 2013 at 09:09:48PM +0200, Johannes Gerer wrote: What about these two very simple type classes. Are they equivalent? [...] class Pointed f where pure :: a - f a class Unit f where unit :: f a a newtype UnitPointed f a = UnitPointed f a a instance Unit f = Pointed

Re: [Haskell-cafe] Type classes

2013-05-28 Thread Johannes Gerer
Dear Tom, I really appreciate your help, but If I could ask the perfect question I probably would already know the answer... My example should not prove anything, instead they collectively show, that I am missing something. And it is not the fact, that pure f does not depend on f. If, however,

Re: [Haskell-cafe] Type classes

2013-05-28 Thread Tom Ellis
On Tue, May 28, 2013 at 11:22:22PM +0200, Johannes Gerer wrote: I have to ask, why was plausability and looking at the actual definition (not just the types) not important for the other examples. It would also be important to check the definitions in the other examples too, but it's hard enough

Re: [Haskell-cafe] Type classes, collections, sum types, closures, and a massive headache

2013-01-31 Thread Bob Hutchison
Thanks everyone, I very much appreciate your help, and I think it did help. I've spent the last few days implementing a substantial chunk of my system using each of two different techniques. I've ended up going with and ADT containing functions closed over the 'thing'. This seems to be the

Re: [Haskell-cafe] Type classes, collections, sum types, closures, and a massive headache

2013-01-31 Thread Bob Hutchison
for your convenience, the correct link: https://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] Type classes, collections, sum types, closures, and a massive headache

2013-01-30 Thread Tim Docker
On 29/01/2013, at 12:43 PM, Bob Hutchison hutch-li...@recursive.ca wrote: The immediate problem is mapping an input to the system, some json message containing a reference to the 'thing' (like a key of some kind). I have to take that reference and find the thing and operate on it. All

Re: [Haskell-cafe] Type classes, collections, sum types, closures, and a massive headache

2013-01-29 Thread Evan Laforge
Today I thought it was about time to simplify how new 'things' of a certain kind are added to the system. These things are some a cross between an event and an assertion of a fact in a rule based system. There are many different kinds of these things. I already have more than a dozen

[Haskell-cafe] Type classes, collections, sum types, closures, and a massive headache

2013-01-28 Thread Bob Hutchison
Hi, I'm relatively new to Haskell, and consider myself to be towards the beginner side of the scale. Nevertheless, I've got this Haskell program I've been working on that's sitting around 11k lines right now. The pattern has been to let it grow to then knock it back by 'refactoring' or

Re: [Haskell-cafe] Type classes, collections, sum types, closures, and a massive headache

2013-01-28 Thread Taylor Hedberg
If I understand your message well enough, I think you are looking for GHC's `ExistentialQuantification` extension. Building heterogeneous collections is a common example of what existential types are useful for. Take a look at this wiki page [1]; there is an example of how to accomplish this

Re: [Haskell-cafe] Type classes, collections, sum types, closures, and a massive headache

2013-01-28 Thread Darren Grant
On Mon, Jan 28, 2013 at 5:43 PM, Bob Hutchison hutch-li...@recursive.cawrote: Now, this is how I got caught: it seems to be impossible to have collections of things with a common type class if they have different types. How is it that I've written that many lines of code in Haskell and I'm

[Haskell-cafe] Type classes for converting to Text and String

2012-03-08 Thread Simon Hengel
Hi! When writing library code that should work with both String and Text I find my self repeatedly introducing classes like: class ToString a where toString :: a - String class ToText a where toText :: a - Text (I use this with newtype wrapped value types backed by Text or

Re: [Haskell-cafe] Type classes for converting to Text and String

2012-03-08 Thread Christopher Done
On 8 March 2012 10:53, Simon Hengel s...@typeful.net wrote: When writing library code that should work with both String and Text I find my self repeatedly introducing classes like:    class ToString a where      toString :: a - String    class ToText a where      toText :: a - Text Text

Re: [Haskell-cafe] Type classes for converting to Text and String

2012-03-08 Thread Roman Cheplyaka
* Simon Hengel s...@typeful.net [2012-03-08 10:53:15+0100] When writing library code that should work with both String and Text I find my self repeatedly introducing classes like: [...] How do you guys deal with that? Any thoughts? If it's fine to depend on FunDeps, you can use ListLike.

Re: [Haskell-cafe] Type classes for converting to Text and String

2012-03-08 Thread Simon Hengel
On Thu, Mar 08, 2012 at 11:00:34AM +0100, Christopher Done wrote: On 8 March 2012 10:53, Simon Hengel s...@typeful.net wrote: When writing library code that should work with both String and Text I find my self repeatedly introducing classes like:    class ToString a where      toString

Re: [Haskell-cafe] Type classes for converting to Text and String

2012-03-08 Thread Simon Hengel
On Thu, Mar 08, 2012 at 12:18:56PM +0200, Roman Cheplyaka wrote: If it's fine to depend on FunDeps, you can use ListLike. http://hackage.haskell.org/package/ListLike How would that help with toText? Cheers, Simon ___ Haskell-Cafe mailing list

Re: [Haskell-cafe] Type classes for converting to Text and String

2012-03-08 Thread Roman Cheplyaka
* Simon Hengel s...@typeful.net [2012-03-08 11:48:41+0100] On Thu, Mar 08, 2012 at 12:18:56PM +0200, Roman Cheplyaka wrote: If it's fine to depend on FunDeps, you can use ListLike. http://hackage.haskell.org/package/ListLike How would that help with toText? toText = fromListLike

Re: [Haskell-cafe] Type classes for converting to Text and String

2012-03-08 Thread Yves Parès
If you just need to go back and forth from String to Text, why do you need to be generic? pack and unpack from Data.Text do the job. Plus, in the way of what Christopher said, you can use the OverloadedStrings extension. You can then use the string syntax at a place that expects a text: {-#

Re: [Haskell-cafe] Type classes for converting to Text and String

2012-03-08 Thread Simon Hengel
On Thu, Mar 08, 2012 at 12:37:31PM +0100, Yves Parès wrote: If you just need to go back and forth from String to Text, why do you need to be generic? pack and unpack from Data.Text do the job. Always going through String or Text may (depending on what your underlying representation is) be less

Re: [Haskell-cafe] Type classes for converting to Text and String

2012-03-08 Thread Simon Hengel
On Thu, Mar 08, 2012 at 12:54:13PM +0200, Roman Cheplyaka wrote: * Simon Hengel s...@typeful.net [2012-03-08 11:48:41+0100] On Thu, Mar 08, 2012 at 12:18:56PM +0200, Roman Cheplyaka wrote: If it's fine to depend on FunDeps, you can use ListLike. http://hackage.haskell.org/package/ListLike

Re: [Haskell-cafe] Type classes for converting to Text and String

2012-03-08 Thread Roman Cheplyaka
* Simon Hengel s...@typeful.net [2012-03-08 13:20:22+0100] On Thu, Mar 08, 2012 at 12:54:13PM +0200, Roman Cheplyaka wrote: * Simon Hengel s...@typeful.net [2012-03-08 11:48:41+0100] On Thu, Mar 08, 2012 at 12:18:56PM +0200, Roman Cheplyaka wrote: If it's fine to depend on FunDeps, you

[Haskell-cafe] Type classes in Typing Haskell in Haskell

2011-12-29 Thread Alexander Bau
Hi, recently I tried the Typing Haskell in Haskell library. But I was wondering why this program type checks: -- plusMfun is standard '+': Num a = a - a - a test = let Just classEnv = ( addCoreClasses : addNumClasses ) initialEnv e = Ap ( Ap (Var +) (Lit $ LitStr 3)) (Lit $ LitStr

[Haskell-cafe] Type Classes in Haskell - how can I make GHC make a choice of types, when the type chosen doesn't matter?

2011-04-14 Thread Chris Dew
This is a question about the use of type classes in Haskell. I get an error (below) when trying to compile the code (below and at https://github.com/chrisdew/haskell-sandbox/blob/master/not_working_but_clean.hs ). As someone just learning Haskell, I have tried following GHC's advice, but I think

Re: [Haskell-cafe] Type Classes in Haskell - how can I make GHC make a choice of types, when the type chosen doesn't matter?

2011-04-14 Thread Neil Brown
On 14/04/11 13:00, Chris Dew wrote: class Stream a b c d where (-) :: a - (b - c) - d instance Stream (IO d) d (IO c) (IO c) where f - g = f= g instance Stream d d (IO c) (IO c) where f - g = g f instance Stream d d c c where x - y = y $ x I notice that in all

Re: [Haskell-cafe] Type Classes in Haskell - how can I make GHC make a choice of types, when the type chosen doesn't matter?

2011-04-14 Thread Stephen Tetley
Hi Chris What does the Stream class *do* though? class Stream a b c d where (-) :: a - (b - c) - d Even with Neil's change its still quite unusual: class Stream a b c where (-) :: a - (b - c) - c In the first formulation there is an input of type a, a function (b - c) and a result of

Re: [Haskell-cafe] Type Classes in Haskell - how can I make GHC make a choice of types, when the type chosen doesn't matter?

2011-04-14 Thread Chris Dew
@Neil Brown - That did it. It's not the ideal solution, as all - are 'coerced' into being 'IO x' (if the rightmost term is an 'IO x'. But it'll do for the time being. Many thanks, Chris. On 14 April 2011 13:50, Neil Brown nc...@kent.ac.uk wrote: On 14/04/11 13:00, Chris Dew wrote: class

Re: [Haskell-cafe] Type Classes in Haskell - how can I make GHC make a choice of types, when the type chosen doesn't matter?

2011-04-14 Thread Chris Dew
@Stephen Tetley - The stream class exists simply to allow for the creation of a - operator which can be used to 'Stream' data through multiple pure and IO functions, on the way to some form of output. It's probably not a great idea, as there are more idiomatic solutions in Haskell - I'm sure

Re: [Haskell-cafe] Type Classes in Haskell - how can I make GHC make a choice of types, when the type chosen doesn't matter?

2011-04-14 Thread Stephen Tetley
On 14 April 2011 20:35, Chris Dew cms...@gmail.com wrote: Could you suggest how these constraints could be expressed in the Haskell type system? Hi Chris I'm afriad I'd have to decline - generally in Haskell implicit lifters are problematic, so it isn't something I'd be looking to solve.

Re: [Haskell-cafe] Type Classes in Haskell - how can I make GHC make a choice of types, when the type chosen doesn't matter?

2011-04-14 Thread Chris Dew
Thanks, that link's very relevant to what I'm trying. For the time being I'll accept a partial solution where the last two types are now the same, and try to improve it when my knowledge of Haskell improves. I really want (hello - bracket) in (hello - bracket - putStrLn) to have a type of

Re: [Haskell-cafe] type classes and logic

2010-08-28 Thread Patrick Browne
Daniel Fischer wrote: class BEING human = HUMAN human where Sub-classing is logical implication BEING(human) = HUMAN(human) All types t that make BEING(t) = true also make HUMAN(t)=true No, it's the other way round. Every HUMAN is also a BEING, hence HUMAN(t) = BEING(t) Could I say

Re: [Haskell-cafe] type classes and logic

2010-08-28 Thread Sebastian Fischer
Daniel Fischer wrote: class BEING human = HUMAN human where Sub-classing is logical implication BEING(human) = HUMAN(human) All types t that make BEING(t) = true also make HUMAN(t)=true No, it's the other way round. Every HUMAN is also a BEING, hence HUMAN(t) = BEING(t) Could I say that

Re: [Haskell-cafe] type classes and logic

2010-08-28 Thread Brandon S Allbery KF8NH
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 8/28/10 06:17 , Patrick Browne wrote: In the light of the above examples how should I interpret the class-to-subclass relation as logical implication? Is it a) If BEING then HUMAN (sufficient condition): BEING = HUMAN b) HUMAN is true only if

[Haskell-cafe] type classes and logic

2010-08-27 Thread Patrick Browne
Hi, I am trying to understand type classes and sub-classes in purely logical terms From the literature I gather that: 1)a type class is a predicate over types (using type variables) 2)type sub-classing is a logical implication between these predicates. But I feel that 1) and 2) does not give

Re: [Haskell-cafe] type classes and logic

2010-08-27 Thread Daniel Fischer
On Friday 27 August 2010 14:54:53, Patrick Browne wrote: class BEING human  = HUMAN human where At this point there is no additional functionality is defined for the subclass HUMAN Sub-classing is logical implication BEING(human)  = HUMAN(human) All types t that make BEING(t) = true also

Re: [Haskell-cafe] type classes and logic

2010-08-27 Thread Sebastian Fischer
Hi Pat, A proof for the predicate BEING(being) must show that there is an inhabited type (a type which has values) Note that in a lazy language like Haskell every type is inhabited by _| _, that is, bottom the undefined value. If we find a value for a type that is a proof that a type

Re: [Haskell-cafe] type classes and logic

2010-08-27 Thread Patrick Browne
Sebastian, Thanks for your very useful reply. Does the EQ example below not talk about inhabited types as proofs. Thanks, Pat Sebastian Fischer wrote: If we find a value for a type that is a proof that a type exists (it is inhabited) that is a member of the class I don't understand the

Re: [Haskell-cafe] Type classes

2010-07-04 Thread Ivan Lazar Miljenovic
Andrew Coppin andrewcop...@btinternet.com writes: In summary, I think we need to devise a way of better-documenting class instances. Haddock 2.7 supports documenting instance implementations; I don't know how this works, but according to the Changelog it's available. -- Ivan Lazar

Re: [Haskell-cafe] Type classes

2010-07-04 Thread Ross Paterson
On Sun, Jul 04, 2010 at 09:55:53PM +1000, Ivan Lazar Miljenovic wrote: Andrew Coppin andrewcop...@btinternet.com writes: In summary, I think we need to devise a way of better-documenting class instances. Haddock 2.7 supports documenting instance implementations; I don't know how this

Re: [Haskell-cafe] Type classes

2010-07-04 Thread Ivan Lazar Miljenovic
Ross Paterson r...@soi.city.ac.uk writes: On Sun, Jul 04, 2010 at 09:55:53PM +1000, Ivan Lazar Miljenovic wrote: Andrew Coppin andrewcop...@btinternet.com writes: In summary, I think we need to devise a way of better-documenting class instances. Haddock 2.7 supports documenting instance

Re: [Haskell-cafe] Type classes

2010-07-04 Thread David Waern
2010/7/4 Ivan Lazar Miljenovic ivan.miljeno...@gmail.com: Andrew Coppin andrewcop...@btinternet.com writes: In summary, I think we need to devise a way of better-documenting class instances. Haddock 2.7 supports documenting instance implementations; I don't know how this works, but

Re: [Haskell-cafe] Type classes

2010-07-04 Thread Daniel Fischer
On Sunday 04 July 2010 14:07:03, Ivan Lazar Miljenovic wrote: Ross Paterson r...@soi.city.ac.uk writes: On Sun, Jul 04, 2010 at 09:55:53PM +1000, Ivan Lazar Miljenovic wrote: Andrew Coppin andrewcop...@btinternet.com writes: In summary, I think we need to devise a way of better-documenting

Re: [Haskell-cafe] Type classes

2010-07-04 Thread Daniel Fischer
On Sunday 04 July 2010 14:03:51, Ross Paterson wrote: Now we need to go round and document our instances. Hmm, it seems only partial: documentation attached to an instance is shown in the list of instances under a type, but not the list under a class. Not much of a problem. Right-click on

Re: [Haskell-cafe] Type classes

2010-07-04 Thread David Waern
2010/7/4 Daniel Fischer daniel.is.fisc...@web.de: Hmm, it seems only partial: documentation attached to an instance is shown in the list of instances under a type, but not the list under a class. I'm guessing that's to reduce noise... I'm guessing it might have something to do with the

Re: [Haskell-cafe] Type classes

2010-07-04 Thread Ross Paterson
On Sun, Jul 04, 2010 at 02:32:35PM +0200, Daniel Fischer wrote: On Sunday 04 July 2010 14:07:03, Ivan Lazar Miljenovic wrote: Ross Paterson r...@soi.city.ac.uk writes: Hmm, it seems only partial: documentation attached to an instance is shown in the list of instances under a type, but not

Re: [Haskell-cafe] Type classes

2010-07-04 Thread Ivan Lazar Miljenovic
David Waern david.wa...@gmail.com writes: 2010/7/4 Ivan Lazar Miljenovic ivan.miljeno...@gmail.com: Andrew Coppin andrewcop...@btinternet.com writes: In summary, I think we need to devise a way of better-documenting class instances. Haddock 2.7 supports documenting instance

Re: [Haskell-cafe] Type classes

2010-07-04 Thread David Waern
2010/7/4 Ivan Lazar Miljenovic ivan.miljeno...@gmail.com: David Waern david.wa...@gmail.com writes: 2010/7/4 Ivan Lazar Miljenovic ivan.miljeno...@gmail.com: Andrew Coppin andrewcop...@btinternet.com writes: In summary, I think we need to devise a way of better-documenting class instances.

Re: [Haskell-cafe] Type classes

2010-07-04 Thread David Waern
2010/7/4 Ross Paterson r...@soi.city.ac.uk: It could be either way: sometimes you define a new class with instances for existing types, and with the current implementation that produces no documentation. (I tested with type, class and instance in the same package.) Hi Ross, thanks for

Re: [Haskell-cafe] Type classes

2010-07-04 Thread David Waern
2010/7/4 David Waern david.wa...@gmail.com: 2010/7/4 Daniel Fischer daniel.is.fisc...@web.de: Hmm, it seems only partial: documentation attached to an instance is shown in the list of instances under a type, but not the list under a class. I'm guessing that's to reduce noise... I'm

Re: [Haskell-cafe] Type classes

2010-07-04 Thread Andrew Coppin
David Waern wrote: I found the bug and fixed it, it's in the latest darcs version Open Source Works.(tm) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

[Haskell-cafe] Type classes

2008-12-26 Thread Oscar Picasso
From Real World Haskell: data JValue = JString String | JNumber Double | JBool Bool | JNull | JObject [(String, JValue)] | JArray [JValue] deriving (Eq, Ord, Show) type JSONError = String class JSON a where

Re: [Haskell-cafe] Type classes vr.s functions

2008-12-24 Thread Brian Hurt
On Tue, 23 Dec 2008, wren ng thornton wrote: In particular, imagine that you have two different and valid ways to convert the same type into Foo; which do you choose? With the continuation/combinator/argument approach this is a non-issue since you can just pass in the one you need. With

Re: [Haskell-cafe] Type classes vr.s functions

2008-12-23 Thread wren ng thornton
Brian Hurt wrote: So, style question for people, if I can. I have a certain problem- basically, I have a bunch of functions which need a special function, of type a - Foo say. And a bunch of other functions which can define that function on some type of interest, and then what to call the

[Haskell-cafe] Type classes vr.s functions

2008-12-20 Thread Brian Hurt
So, style question for people, if I can. I have a certain problem- basically, I have a bunch of functions which need a special function, of type a - Foo say. And a bunch of other functions which can define that function on some type of interest, and then what to call the first batch of

Re: [Haskell-cafe] Type classes vr.s functions

2008-12-20 Thread Brandon S. Allbery KF8NH
On 2008 Dec 20, at 20:20, Brian Hurt wrote: class Fooable a where toFoo :: a - Foo or I can simply have all the functions which need a toFoo take an extra agrument. Performance really isn't that important here, so it's really a matter of style- which approach would people prefer in this

Re: [Haskell-cafe] Type classes vr.s functions

2008-12-20 Thread Luke Palmer
On Sat, Dec 20, 2008 at 6:20 PM, Brian Hurt bh...@spnz.org wrote: So, style question for people, if I can. I have a certain problem- basically, I have a bunch of functions which need a special function, of type a - Foo say. And a bunch of other functions which can define that function on

Re: [Haskell-cafe] Type classes question

2008-10-07 Thread Ryan Ingram
On Tue, Oct 7, 2008 at 1:13 PM, Roly Perera [EMAIL PROTECTED] wrote: Hi, I'm reasonably well versed in Haskell but fairly new to defining type classes. In particular I don't really understand how to arrange for all instances of X to also be instances of Y. It's quite possibly that my

[Haskell-cafe] Type classes question

2008-10-07 Thread Roly Perera
Hi, I'm reasonably well versed in Haskell but fairly new to defining type classes. In particular I don't really understand how to arrange for all instances of X to also be instances of Y. It's quite possibly that my question is ill-posed, so I'll make it as concrete as possible: in the

Re: [Haskell-cafe] Type classes question

2008-10-07 Thread Bulat Ziganshin
Hello Roly, Tuesday, October 7, 2008, 4:13:25 PM, you wrote: I'm reasonably well versed in Haskell but fairly new to defining type classes. http://haskell.org/haskellwiki/OOP_vs_type_classes may be useful -- Best regards, Bulatmailto:[EMAIL PROTECTED]

Re: [Haskell-cafe] type classes

2008-07-03 Thread Cotton Seed
Hi Henning, The numeric prelude was inspiration for a lot of my design. Part of the reason I didn't use it was because one of my goals is to learn Haskell better, and I wanted to grapple with these design decisions myself. I decided, like IsZeroTestable in the numeric prelude, to make zero/one

[Haskell-cafe] type classes

2008-07-02 Thread Cotton Seed
Hi everyone, I'm working on a computational algebra program and I've run into a problem. In my program, I have types for instances of algebraic objects, e.g. ZModN for modular integers, and types for the objects themselves, e.g. ZModNTy for the ring of modular integers. Now, I want to subclass

Re: [Haskell-cafe] type classes

2008-07-02 Thread Dan Doel
On Wednesday 02 July 2008, Cotton Seed wrote: Hi everyone, I'm working on a computational algebra program and I've run into a problem. In my program, I have types for instances of algebraic objects, e.g. ZModN for modular integers, and types for the objects themselves, e.g. ZModNTy for the

Re: [Haskell-cafe] type classes

2008-07-02 Thread Cotton Seed
Hi Dan, Thanks! This is exactly what I was looking for. Cotton On Wed, Jul 2, 2008 at 9:57 PM, Dan Doel [EMAIL PROTECTED] wrote: On Wednesday 02 July 2008, Cotton Seed wrote: Hi everyone, I'm working on a computational algebra program and I've run into a problem. In my program, I

Re: [Haskell-cafe] type classes

2008-07-02 Thread Henning Thielemann
On Wed, 2 Jul 2008, Cotton Seed wrote: Hi everyone, I'm working on a computational algebra program and I've run into a problem. In my program, I have types for instances of algebraic objects, e.g. ZModN for modular integers, and types for the objects themselves, e.g. ZModNTy for the ring of

[Haskell-cafe] type classes

2007-12-14 Thread Peter Padawitz
I'd like to define several instances of the same type class with the same type variable instance. Only method instances differ. How can I do this without writing copies of the type class? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] type classes

2007-12-14 Thread Jules Bean
Peter Padawitz wrote: I'd like to define several instances of the same type class with the same type variable instance. Only method instances differ. How can I do this without writing copies of the type class? newtypes and modules have both been suggested. I have another suggestion: Don't!

Re: [Haskell-cafe] type classes

2007-12-14 Thread Ketil Malde
Lutz Donnerhacke [EMAIL PROTECTED] writes: * Peter Padawitz wrote: I'd like to define several instances of the same type class with the same type variable instance. Only method instances differ. How can I do this without writing copies of the type class? Define the type class in a module

Re: [Haskell-cafe] type classes

2007-12-14 Thread Lutz Donnerhacke
* Peter Padawitz wrote: I'd like to define several instances of the same type class with the same type variable instance. Only method instances differ. How can I do this without writing copies of the type class? Define the type class in a module named MyClass. Define the each instance in a

[Haskell-cafe] Type classes: Missing language feature?

2007-08-07 Thread DavidA
Hi, there's something I'm trying to do with type classes that seems to fit very naturally with my mental model of type classes, but doesn't seem to be supported by the language. I'm wondering whether I'm missing something, or whether there's some language extension that could help me or

Re: [Haskell-cafe] Type classes: Missing language feature?

2007-08-07 Thread Derek Elkins
On Tue, 2007-08-07 at 12:58 +, DavidA wrote: Hi, there's something I'm trying to do with type classes that seems to fit very naturally with my mental model of type classes, but doesn't seem to be supported by the language. I'm wondering whether I'm missing something, or whether

Re: [Haskell-cafe] Type classes: Missing language feature?

2007-08-07 Thread Tillmann Rendel
DavidA wrote: Now, what I'd like to do is have Lex and Glex, and any further monomial orderings I define later, automatically derive Show and Num instances from Monomial (because it seems like boilerplate to have to define Show and Num instances by hand). Something like the following (not

[Haskell-cafe] Type classes and type equality

2007-04-16 Thread Neil Mitchell
Hi, I'm looking for a type class which checks whether two types are the same or not. My first guess is: class Same a b where same :: a - b - Bool instance Same a a where same _ _ = True instance Same a b where same _ _ = False In Hugs this seems to work with overlapping instances (not

Re: [Haskell-cafe] Type classes and type equality

2007-04-16 Thread Jeremy Shaw
At Mon, 16 Apr 2007 13:44:13 +0100, Neil Mitchell wrote: Hi, So my question is if this is safe? Will the compiler always pick the right one? Is there a better way to do this? I noticed that the results can be a bit suprising sometimes. See if you can predict the answers to these (in ghci):

Re: [Haskell-cafe] Type classes and type equality

2007-04-16 Thread Clifford Beshers
Jeremy Shaw wrote: I noticed that the results can be a bit suprising sometimes. See if you can predict the answers to these (in ghci): Interesting examples. Here's another one that I would find problematic: *SameType same Nothing (Just xyzzy) False *SameType same (Nothing ::

[Haskell-cafe] Type classes to 'reflect' constructor structure

2007-04-05 Thread Jules Bean
In the thread 'automatic derivation', Joel Reymont is looking for metaprogramming functionality with which he wants to automatically derive a parser and a pretty printer for his ADT (which is an AST for a minilanguage). I replied showing that a significant amount of the boilerplate could be

[Haskell-cafe] Type classes

2006-03-20 Thread Max Vasin
Hi! I'm currently experimenting with a bibliography generation tool for LaTeX. It will (if it will be finished) use BibTeX databases but bibliography styles will be written in Haskell. I want styles to be able to transform database entries into some style specific data type, so I define class

Re: [Haskell-cafe] Type classes

2006-03-20 Thread Stefan Holdermans
Max, class DatabaseEntry e where entryLabel :: e - String formatEntry:: e - String compareEntries :: e - e - Ordering Then I define data Entry = forall a. (DatabaseEntry a) = Entry a instance DatabaseEntry Entry where entryLabel (Entry e) = entryLabel e

RE: [Haskell-cafe] Type classes

2006-03-20 Thread Geest, G. van den
Title: RE: [Haskell-cafe] Type classes I suppose you want to define compareEntries like this: compareEntries (Entry x) (Entry y) = compareEntries x y An option is to just implement it the following way (Haskell98!): class DatabaseEntry e where entryLabel :: e - String formatEntry :: e

Re: [Haskell-cafe] Type classes

2006-03-20 Thread Matthias Fischmann
Vasin wrote: To: haskell-cafe@haskell.org From: Max Vasin [EMAIL PROTECTED] Date: Mon, 20 Mar 2006 17:46:43 +0300 Subject: [Haskell-cafe] Type classes Hi! I'm currently experimenting with a bibliography generation tool for LaTeX. It will (if it will be finished) use BibTeX databases

Re: [Haskell-cafe] Type classes and hFoldr from HList

2005-11-07 Thread Greg Buchholz
Ralf Lammel wrote: What you can do is define a dedicated *type code* for composition. comp = hFoldr (undefined::Comp) (id::Int - Int) test data Comp instance Apply Comp (x - y,y - z) (x - z) where apply _ (f,g) = g . f That does it! Thanks, Greg Buchholz

[Haskell-cafe] Type classes and hFoldr from HList

2005-11-06 Thread Greg Buchholz
I was playing around with the HList library from the paper... Strongly typed heterogeneous collections http://homepages.cwi.nl/~ralf/HList/ ...and I thought I'd try to fold the composition function (.) through a heterogeneous list of functions, using hFoldr... {-# OPTIONS

RE: [Haskell-cafe] Type classes and hFoldr from HList

2005-11-06 Thread Ralf Lammel
-Original Message- From: [EMAIL PROTECTED] [mailto:haskell-cafe- [EMAIL PROTECTED] On Behalf Of Greg Buchholz Sent: Sunday, November 06, 2005 7:01 PM To: haskell-cafe@haskell.org Subject: [Haskell-cafe] Type classes and hFoldr from HList I was playing around with the HList library from

Re: [Haskell-cafe] Type classes... popular for newbies, isn't it?

2004-08-09 Thread Stefan Holdermans
Arjun, AG This class definition is giving me a lot of problems AG with the successor function: class (Ord st) = MinimaxState st where successors :: st - [(action, st)] terminal :: st - Bool instance MinimaxState Int where terminal i = i == 0 successors i = [(1,i+1),

Re: [Haskell-cafe] Type classes... popular for newbies, isn't it?

2004-08-09 Thread Stefan Holdermans
Arjan, AG I'm curious as to why my class declaration AG compiles in GHC, as there doesn't seem to AG be any way to use it. class (Ord st) = MinimaxState st where successors :: forall a . st - [(a, st)] terminal :: st - True Any implementation of the successors method needs to produce

Re: [Haskell-cafe] Type classes... popular for newbies, isn't it?

2004-08-07 Thread Stefan Holdermans
Arjun, AG This class definition is giving me a lot of problems AG with the successor function: class (Ord st) = MinimaxState st where successors :: st - [(action, st)] terminal :: st - Bool instance MinimaxState Int where terminal i = i == 0 successors i = [(1,i+1), (-1,i-1)]

Re: [Haskell-cafe] Type classes... popular for newbies, isn't it?

2004-08-07 Thread Arjun Guha
I'd rather not do that, but even if I did, the type-variable action would not be reachable in the terminal function. I could specify a functional dependency st - action (though I've never used it, it would be a fun to learn). I'm curious as to why my class declaration compiles in GHC, as

Re: [Haskell-cafe] Type classes... popular for newbies, isn't it?

2004-08-07 Thread Stefan Holdermans
Arjan, AG I'm curious as to why my class declaration AG compiles in GHC, as there doesn't seem to AG be any way to use it. class (Ord st) = MinimaxState st where successors :: forall a . st - [(a, st)] terminal :: st - True Any implementation of the successors method needs to produce

Re: [Haskell-cafe] Type classes... popular for newbies, isn't it?

2004-08-07 Thread camarao
How about inserting one more parameter, action, in your class definition: class (Ord st) = MinimaxState st action where successors:: st - [(action,st)] terminal:: st - Bool instance MinimaxState Int Int where terminal i = i == 0 successors i = [(1,i+1), (-1,i-1)] I'd rather

[Haskell-cafe] Type classes... popular for newbies, isn't it?

2004-08-06 Thread Arjun Guha
This class definition is giving me a lot of problems with the successor function: class (Ord st) = MinimaxState st where successors:: st - [(action,st)] terminal:: st - Bool A trivial example would be: instance MinimaxState Int where terminal i = i == 0 successors i = [(1,i+1), (-1,i-1)]