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
|
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
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
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
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 =
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
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
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
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
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
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
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
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
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
- 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
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
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
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
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
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 ::
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) =
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
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
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
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
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
--- 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,
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
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
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
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
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
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
(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
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
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
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
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
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
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;
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
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
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
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
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
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)"
46 matches
Mail list logo