[Haskell-cafe] Re: Type classes

2008-12-26 Thread Oscar Picasso
Forget it. It's more clear reading further. Sorry for the noise. On Sat, Dec 27, 2008 at 1:02 AM, Oscar Picasso oscarpica...@gmail.comwrote: From Real World Haskell: data JValue = JString String | JNumber Double | JBool Bool | JNull |

Re: Type classes in GADTs

2008-10-30 Thread Jason Dagit
On Wed, Oct 29, 2008 at 10:20 PM, C Rodrigues [EMAIL PROTECTED] wrote: I discovered that closed type classes can be implicitly defined using GADTs The GADT value itself acts like a class dictionary. However, GHC (6.83) doesn't know anything about these type classes, and it won't infer any

Re: Type classes in GADTs

2008-10-30 Thread Daniil Elovkov
Jason Dagit wrote: On Wed, Oct 29, 2008 at 10:20 PM, C Rodrigues [EMAIL PROTECTED] wrote: I discovered that closed type classes can be implicitly defined using GADTs The GADT value itself acts like a class dictionary. However, GHC (6.83) doesn't know anything about these type classes, and

RE: Type classes in GADTs

2008-10-30 Thread C Rodrigues
Thanks for the explanation. I see how this wouldn't behave nicely with automatic class constraint inference. I didn't test the example on any other GHC versions. I will probably end up passing in the Eq dictionary from outside like Daniil suggested. I would prefer to do the following, but

Re: Type classes in GADTs

2008-10-30 Thread Thomas Schilling
2008/10/30 C Rodrigues [EMAIL PROTECTED]: evidenceOfEq :: CAOp a - (Eq a = b) - b isn't that the same as: evidenceOfEq :: Eq a = CAOp a - b - b Neither does it accept data EqConstraint a b = EqConstraint (Eq a = b). Foiled again. same here: data Eq a = EqConstraint a b =

[Haskell-cafe] Re: Type classes question

2008-10-08 Thread Roly Perera
Ryan Ingram ryani.spam at gmail.com writes: [...] Here's another possible solution: newtype AsFunctor s a = AF { fstream :: (s a) } instance (Stream f) = Functor (AsFunctor f) where fmap f (AF s) = AF (fmapStreamDefault f s) Now to use fmap you wrap in AF and unwrap with

[Haskell-cafe] Re: type classes

2008-07-07 Thread Chung-chieh Shan
class RingTy a b where order :: a - Integer units :: a - [b] class VectorSpaceTy a b | a - b where dimension :: a - Integer basis :: (Field c) = a - [b c] where `b' is a vector space over the field `c'. It looks like you are using the first (of two) type arguments to the RingTy

[Haskell-cafe] Re: type classes

2008-07-03 Thread DavidA
Slightly off-topic - but I'm curious to know why you want objects representing the structures as well as the elements - what will they be used for? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] Re: type classes

2008-07-03 Thread Cotton Seed
A number of operations -- like order above -- are conceptually connected not to the elements but to the structures themselves. Here is the outline of a more complicated example. I also have a vector space class class VectorSpaceTy a b | a - b where dimension :: a - Integer basis :: (Field

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

2007-08-07 Thread apfelmus
DavidA wrote: newtype Lex = Lex Monomial deriving (Eq) newtype Glex = Glex Monomial deriving (Eq) 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

Re: Type classes vs C++ overloading Re: [Haskell-cafe] Messing around with types [newbie]

2007-06-22 Thread Cristiano Paris
Paris [EMAIL PROTECTED] Date: Jun 21, 2007 6:20 PM Subject: Re: Type classes vs C++ overloading Re: [Haskell-cafe] Messing around with types [newbie] To: Bulat Ziganshin [EMAIL PROTECTED] On 6/21/07, Bulat Ziganshin [EMAIL PROTECTED] wrote: Hello Cristiano, Thursday, June 21, 2007, 4:46:27 PM

Re: Type classes vs C++ overloading Re: [Haskell-cafe] Messing around with types [newbie]

2007-06-22 Thread Tomasz Zielonka
On Fri, Jun 22, 2007 at 10:57:58AM +0200, Cristiano Paris wrote: Quoting Bryan: *From this you can see that 10 is not necessarily an Int, and 5.0 is *not necessarily a Double. So the typechecker does not know, given just 10 and 5.0, which instance of 'foo' to use. But when you explicitly

Re: Type classes vs C++ overloading Re: [Haskell-cafe] Messing around with types [newbie]

2007-06-22 Thread Cristiano Paris
On 6/22/07, Tomasz Zielonka [EMAIL PROTECTED] wrote: ... The problem is not that it can't tell whether 5.0 and 10 would fit Int and Double (actually, they do fit), it's that it can't tell if they won't fit another instance of FooOp. You expressed the concept in more correct terms but I

Re: Type classes vs C++ overloading Re: [Haskell-cafe] Messing around with types [newbie]

2007-06-21 Thread Dan Weston
Bulat Ziganshin wrote: Hello Cristiano, Thursday, June 21, 2007, 4:46:27 PM, you wrote: class FooOp a b where foo :: a - b - IO () instance FooOp Int Double where foo x y = putStrLn $ (show x) ++ Double ++ (show y) this is rather typical question :) unlike C++ which resolves any

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

2007-04-19 Thread oleg
- If we permit overlapping instances extension, then a few lines of code decide equality for all existing and future types: class TypeEq x y b | x y - b instance TypeEq x x HTrue instance TypeCast HFalse b = TypeEq x y b This is exactly what I was after, but

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

2007-04-17 Thread Neil Mitchell
Hi Oleg, I'm looking for a type class which checks whether two types are the same or not. For the full discussion of various solutions, please see Section 9 and Appendix D of the HList paper: http://homepages.cwi.nl/~ralf/HList/paper.pdf Thanks for pointing that out. As far as I

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

2007-04-17 Thread oleg
Thanks for pointing that out. As far as I can see, this requires a new instance declaration for every type? I guess it depends on how many extensions one may wish to enable. At the very least we need multi-parameter type classes with functional dependencies (because that's what TypeEq is in

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

2007-04-17 Thread Neil Mitchell
Hi I guess it depends on how many extensions one may wish to enable. At the very least we need multi-parameter type classes with functional dependencies (because that's what TypeEq is in any case). - If we permit no other extension, we need N^2 instances to compare N classes for equality

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

2007-04-17 Thread Stefan O'Rear
On Wed, Apr 18, 2007 at 01:47:04AM +0100, Neil Mitchell wrote: - If we permit undecidable instances, one may assign numerals to types. This gives us total order and hence comparison on types. In this approach, we only need N instances to cover N types. This is still better than Typeable

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

2007-04-16 Thread oleg
Neil Mitchell wrote: I'm looking for a type class which checks whether two types are the same or not. This problem is more complex than appears. It has been solved, however. IncoherentInstances are not required, as IncoherentInstances are generally unsafe. For the full discussion of various

[Haskell-cafe] Re: Type classes

2006-03-20 Thread Max Vasin
Geest, == Geest, G van den [EMAIL PROTECTED] writes: Geest, I suppose you want to define compareEntries like this: compareEntries (Entry x) (Entry y) = compareEntries x y Geest, An option is to just implement it the following way Geest, (Haskell98!): class DatabaseEntry e where entryLabel ::

Re: [Haskell-cafe] Re: Type classes

2006-03-20 Thread Gerrit van den Geest
Then you should produce 'some canonical representation for database entries suited for comparison', like Stefan mentioned. For example: data Entry = forall a. (DatabaseEntry a) = Entry a instance DatabaseEntry Entry where entryLabel (Entry e) = entryLabel e formatEntry (Entry e) =

[Haskell-cafe] Re: Type classes

2006-03-20 Thread Max Vasin
Stefan == Stefan Holdermans [EMAIL PROTECTED] writes: Stefan 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

Re: [Haskell-cafe] Re: Type classes and definite types

2005-05-11 Thread Krasimir Angelov
Hi Bryn Keller, The solution for your problem is very simple. You just have to fetch all values as strings. In this way the library will do all required conversions for you. printRow stmt = do id - getFieldValue stmt ID code - getFieldValue stmt Code name - getFieldValue stmt Name

Re: Type classes confusion

2004-01-10 Thread andrew cooke
Ah. I just need to drop the context from the data type declaration. Sorry, Andrew andrew cooke said: Hi, I'm trying to use type classes and suspect I've got confused somewhere down the line, because I've got to an error message that I don't understand and can't remove. I have a class

Re: type classes, superclass of different kind

2003-12-11 Thread Johannes Waldmann
Robert Will wrote: Note that in an OO programming language with generic classes ... (We shouldn't make our functional designs more different from the OO ones, than they need to be.) why should *we* care :-) more often than not, OO design is resticted and misleading. you see how most OO

RE: type classes, superclass of different kind

2003-12-11 Thread Niklas Broberg
Robert Will wrote: Now I would like to have Collection to be a superclass of Map yielding the following typing reduce :: (Map map a b) = ((a, b) - c) - c - map a b - c Note that in an OO programming language with generic classes (which is in general much less

Re: type classes, superclass of different kind

2003-12-11 Thread David Sankel
--- Robert Will [EMAIL PROTECTED] wrote: -- Here -- is a quesion for the -- most creative of thinkers: which is the design (in -- proper Haskell or a -- wide-spread extension) possibly include much -- intermediate type classes and -- other stuff, that comes nearest to my desire? Hello,

Re: type classes, superclass of different kind

2003-12-11 Thread Brandon Michael Moore
On Thu, 11 Dec 2003, Robert Will wrote: Hello, As you will have noticed, I'm designing a little library of Abstract Data Structuresm here is a small excerpt to get an idea: class Collection coll a where ... (+) :: coll a - coll a - coll a reduce :: (a - b) - b

Re: Type classes and code generation

2003-06-17 Thread Bernard James POPE
I had a discussion with someone over the type class mechanism and would like to clarify something. When I compile this trivial program: module Main where main = putStrLn (show (1 + 2)) with ghc -Wall, the compiler says: Main.lhs:3: Warning: Defaulting the following

Re: Type classes and code generation

2003-06-17 Thread Keith Wansbrough
Alistair Bayley writes: Warning: Defaulting the following constraint(s) to type `Integer' `Num a' arising from the literal `2' at Main.lhs:3 This implies to me that the compiler is generating the code for (+) for the particular instance, rather than using a run-time dispatch

RE: Type classes and code generation

2003-06-17 Thread Bayley, Alistair
Is there some way of preventing the type mechanism from generating code for the instance type, as opposed to the class? I don't understand this question - does the explanation above help? I could have been clearer with my questions. What I was wondering was: is there some situation

Re: Type classes and code generation

2003-06-17 Thread Andreas Rossberg
Bayley, Alistair wrote: When it's applied, the compiler will know the types of the arguments, won't it?. Which means that you would generate a version of double for each (applied) instance of Num. I don't doubt that there's a good reason this is not done: code bloat? or are there simply some

Re: Type classes and code generation

2003-06-17 Thread Keith Wansbrough
Does this also mean that a dictionary class is created for every class, and a dictionary created for every instance? Yes, exactly. Every class is translated to a data type declaration, and every instance is translated to an element of that data type - a dictionary. (Note that you can't

Re: Type classes and code generation

2003-06-17 Thread Hal Daume III
(Moved to the Cafe) Yes, exactly. Every class is translated to a data type declaration, and every instance is translated to an element of that data type - a dictionary. (Note that you can't actually write those declarations in Haskell 98 in general, because they can have polymorphic

Re: Type classes and code generation

2003-06-17 Thread Keith Wansbrough
You need to change the first line to this: data C a = C { pair :: forall b. b - (b,a) } and then it works fine (with -fglasgow-exts). But you've now stepped outside the bounds of Haskell 98. (oops, replying to myself... sure sign of madness! :) ) I hasten to add that this is *not* the

Re: Type classes problem: Could not deduce ...

2003-03-10 Thread Matthias Neubauer
Hi Dirk, [EMAIL PROTECTED] writes: Hello, trying to compile the following program class ClassA a where foo :: a - Int class ClassA a = ClassB b a where toA :: b - a test :: (ClassB b a) = b - Int test x = let y = toA x in let z = foo y in

Re: type classes vs. multiple data constructors

2003-02-17 Thread Andrew J Bromage
G'day. On Mon, Feb 17, 2003 at 01:44:07AM -0500, Mike T. Machenry wrote: I was wondering if it's better to define them as type classes with the operations defined in the class. What do haskellian's do? I can't speak for other Haskellians, but on the whole, it depends. Here's the common

Re: type classes and generality

2001-07-09 Thread Fergus Henderson
On 09-Jul-2001, Norman Ramsey [EMAIL PROTECTED] wrote: I'm trying to model probability and leave the representation of probability unspecified other than it must be class Real. But I'm having trouble with random numbers; how can I show that if a type has class Real, it also has class

Re: type classes and generality

2001-07-09 Thread Norman Ramsey
On 09-Jul-2001, Norman Ramsey [EMAIL PROTECTED] wrote: I'm trying to model probability and leave the representation of probability unspecified other than it must be class Real. But I'm having trouble with random numbers; how can I show that if a type has class Real, it also has

Re: type classes and generality

2001-07-09 Thread Fergus Henderson
On 09-Jul-2001, Norman Ramsey [EMAIL PROTECTED] wrote: On 09-Jul-2001, Norman Ramsey [EMAIL PROTECTED] wrote: I'm trying to model probability and leave the representation of probability unspecified other than it must be class Real. But I'm having trouble with random numbers;

Re: type classes and generality

2001-07-09 Thread Alexander V. Voinov
Hi All, Fergus Henderson wrote: Ah, now I think I understand your problem. You want to `random' to generate random numbers that span all the possible values of the type within the range [0, 1], or at least a substantial subset, but the Real class doesn't let you generate any numbers other

Re: type classes and generality

2001-07-09 Thread Fergus Henderson
On 09-Jul-2001, Alexander V. Voinov [EMAIL PROTECTED] wrote: Hi All, Fergus Henderson wrote: Ah, now I think I understand your problem. You want to `random' to generate random numbers that span all the possible values of the type within the range [0, 1], or at least a substantial

Re: type classes and generality

2001-07-09 Thread Lennart Augustsson
Alexander V. Voinov wrote: Hi All, Fergus Henderson wrote: Ah, now I think I understand your problem. You want to `random' to generate random numbers that span all the possible values of the type within the range [0, 1], or at least a substantial subset, but the Real class doesn't

Re: type classes and generality

2001-07-09 Thread Alexander V. Voinov
Hi All, Lennart Augustsson wrote: Each pseudorandom generator generates a countable sequence of values, which is isomorphic to a sequence of integers. In good old (Turbo)C we got something between 0 and MAXINT and then divided by (double)MAXINT. Can't _this_ be done in Haskell? Of

Re: type classes and generality

2001-07-09 Thread Lennart Augustsson
Alexander V. Voinov wrote: Hi All, Lennart Augustsson wrote: Each pseudorandom generator generates a countable sequence of values, which is isomorphic to a sequence of integers. In good old (Turbo)C we got something between 0 and MAXINT and then divided by (double)MAXINT. Can't

Re: Type classes

1997-05-06 Thread F. Warren Burton
A couple of people have asked about: [2] W Burton, E Meijer, P Sansom, S Thompson, P Wadler, "A (sic) extension to Haskell 1.3 for views", sent to the Haskell mailing list 23 Oct 1996 I am enclosing a copy of the "(sic)" proposal below. In light of Simon's proposal, the "(sic)"