Re: Type (class) recursion + families = exponential compile time?

2009-02-26 Thread Lennart Augustsson
Just Hindley-Milner type inference is exponential, making the type system more complex isn't going to make things better. 2009/2/26 Ben Franksen ben.frank...@online.de: Hi the attached module is a much reduced version of some type-level assurance stuff (inspired by the Lightweight Monadic

Re: Type (class) recursion + families = exponential compile time?

2009-02-26 Thread Ben Lippmeier
Here's the reference http://portal.acm.org/citation.cfm?id=96748 Deciding ML typability is complete for deterministic exponential time -- Harry G. Mairson. Ben. On 27/02/2009, at 10:12 AM, Ben Franksen wrote: Hi the attached module is a much reduced version of some type-level

Re: [Haskell-cafe] Re: type class question

2007-12-10 Thread Jules Bean
Try again without missing out the list... Peter Padawitz wrote: Jules Bean wrote: Incidentally, I question why the compFoo are methods. Why not just make them polymorphic functions? They don't look like you expect instances to change them. The code continues to compile if I make them

Re: [Haskell-cafe] Re: type class question

2007-12-10 Thread Peter Padawitz
Jules Bean wrote: Try again without missing out the list... Peter Padawitz wrote: Jules Bean wrote: Incidentally, I question why the compFoo are methods. Why not just make them polymorphic functions? They don't look like you expect instances to change them. The code continues to compile if

Re: [Haskell-cafe] Re: type class question

2007-12-10 Thread Jules Bean
Peter Padawitz wrote: What is so bad about making compFoo part of the class? It reduces the code (constraints can be avoided) and reflects the close connection between a signature Sig (implemented by the class) and the evaluation (compFoo) of Sig-terms in Sig-algebras. making it part of the

Re: [Haskell-cafe] Re: type class question

2007-12-10 Thread Jules Bean
Peter Padawitz wrote: Jules Bean wrote: Peter Padawitz wrote: What is so bad about making compFoo part of the class? It reduces the code (constraints can be avoided) and reflects the close connection between a signature Sig (implemented by the class) and the evaluation (compFoo) of

Re: [Haskell-cafe] Re: type class question

2007-12-10 Thread Peter Padawitz
Jules Bean wrote: Peter Padawitz wrote: Jules Bean wrote: Peter Padawitz wrote: What is so bad about making compFoo part of the class? It reduces the code (constraints can be avoided) and reflects the close connection between a signature Sig (implemented by the class) and the

Re: [Haskell-cafe] Re: type class question

2007-12-10 Thread Bertram Felgenhauer
Peter Padawitz wrote: Jules Bean wrote: I don't see why! In the class class Foo a where f :: a - Int g :: b - Integer g = fromIntegral . f The equations within the class are defaults, not equations. I must admit that I didn't know this... Nevertheless, won't you agree that

Re: [Haskell-cafe] Re: Re: type class question

2007-12-07 Thread Jules Bean
Peter Padawitz wrote: Functional dependencies don't work in my case. Actually, I don't see why they should. Ah well, it's cruel to say that without explaining to us why! I'm not sure why a complete cyclic dep a - b - c - d - a isn't what you want. What seems to be needed here is a type

Re: [Haskell-cafe] Re: Re: type class question

2007-12-07 Thread Peter Padawitz
Functional dependencies don't work in my case. Actually, I don't see why they should. What seems to be needed here is a type class construct with a kind of record parameter so that instance conflicts cannot occur. Jules Bean wrote: Ben Franksen wrote: Ryan Ingram wrote: On 12/5/07, Ben

Re: [Haskell-cafe] Re: Re: type class question

2007-12-07 Thread Jules Bean
Peter Padawitz wrote: Jules Bean wrote: Peter Padawitz wrote: Functional dependencies don't work in my case. Actually, I don't see why they should. Ah well, it's cruel to say that without explaining to us why! Cause I don't see why the instantiation conflicts pointed out by others

Re: [Haskell-cafe] Re: Re: type class question

2007-12-07 Thread Benja Fallenstein
On Dec 7, 2007 6:57 PM, Peter Padawitz [EMAIL PROTECTED] wrote: Jules Bean wrote: Peter Padawitz wrote: Cause I don't see why the instantiation conflicts pointed out by others would vanish then. They would. If it's really true that there is only one possible choice of b,c,d for

Re: [Haskell-cafe] Re: Re: type class question

2007-12-07 Thread Jules Bean
Peter Padawitz wrote: So the fundep would solve the problem. But, actually, it doesn't :-( But actually, it does! Ben Franksen's answer from yesterday compiles fine for me if I add the missing fundep, block - command. Your original code compiles without error, given the fundep. Exact

Re: [Haskell-cafe] Re: Re: type class question

2007-12-07 Thread Luke Palmer
On Dec 7, 2007 5:57 PM, Peter Padawitz [EMAIL PROTECTED] wrote: type Block = [Command] data Command = Skip | Assign String IntE | Cond BoolE Block Block | Loop BoolE Block data IntE= IntE Int | Var String | Sub IntE IntE | Sum [IntE] | Prod [IntE] data BoolE = BoolE Bool | Greater

Re: [Haskell-cafe] Re: Re: type class question

2007-12-07 Thread Peter Padawitz
Jules Bean wrote: Peter Padawitz wrote: Jules Bean wrote: Peter Padawitz wrote: Functional dependencies don't work in my case. Actually, I don't see why they should. Ah well, it's cruel to say that without explaining to us why! Cause I don't see why the instantiation conflicts

Re: [Haskell-cafe] Re: Re: type class question

2007-12-07 Thread Peter Padawitz
Jules Bean wrote: Peter Padawitz wrote: Functional dependencies don't work in my case. Actually, I don't see why they should. Ah well, it's cruel to say that without explaining to us why! Cause I don't see why the instantiation conflicts pointed out by others would vanish then. I'm

[Haskell-cafe] Re: Re: type class question

2007-12-06 Thread Ben Franksen
Ryan Ingram wrote: On 12/5/07, Ben Franksen [EMAIL PROTECTED] wrote: You would have to use functional dependencies or associated types to eliminate this error. Alternatively, you can add a dummy argument of type block and pass undefined :: BlockType in to help choose the instance

Re: [Haskell-cafe] Re: Re: type class question

2007-12-06 Thread Jules Bean
Ben Franksen wrote: Ryan Ingram wrote: On 12/5/07, Ben Franksen [EMAIL PROTECTED] wrote: You would have to use functional dependencies or associated types to eliminate this error. Alternatively, you can add a dummy argument of type block and pass undefined :: BlockType in to help choose the

[Haskell-cafe] Re: type class question

2007-12-05 Thread Ben Franksen
Brent Yorgey wrote: Well, first of all, the definition of compCommand should use calls to compBlock, not recursive calls to compCommand. But that's not the main source of your problems. What exactly are you trying to accomplish? And why do you need a type class? Whatever the code is

Re: [Haskell-cafe] Re: type class question

2007-12-05 Thread Felipe Lessa
On Dec 5, 2007 10:38 PM, Ben Franksen [EMAIL PROTECTED] wrote: data Command = Skip class Java block command where block_ :: [command] - block compBlock :: [Command] - block --compBlock = block_ . map compCommand compCommand :: Command - command My guess is that nothing's

Re: [Haskell-cafe] Re: type class question

2007-12-05 Thread Ryan Ingram
On 12/5/07, Ben Franksen [EMAIL PROTECTED] wrote: data Command = Skip class Java block command where block_ :: [command] - block compBlock :: [Command] - block --compBlock = block_ . map compCommand compCommand :: Command - command This compiles ok. But when I ask ghci for the type of

[Haskell] Re: type class instance selection search

2007-08-01 Thread Chung-chieh Shan
If only for those watching from home, here are some references. jeff p [EMAIL PROTECTED] wrote in article [EMAIL PROTECTED] in gmane.comp.lang.haskell.general: Better yet, how about LambdaProlog ( http://www.lix.polytechnique.fr/Labo/Dale.Miller/lProlog), which generalizes from Horn

[Haskell] Re: type class instance selection search

2007-08-01 Thread apfelmus
Conal Elliott wrote: I keep running into situations in which I want more powerful search in selecting type class instances. One example I raised in June, in which all of the following instances are useful. instance (Functor g, Functor f) = Functor (O g f) where fmap h (O gf) = O (fmap

Re: [Haskell] Re: type class instance selection search

2007-08-01 Thread Wolfgang Jeltsch
Am Mittwoch, 1. August 2007 14:41 schrieb apfelmus: […] The problem with the Functor/Cofunctor instances is that they are ambiguous as soon as a type constructor X is made an instance of both Functor and Cofunctor . Of course, such an X cannot exist in a mathematically useful way

Re: [Haskell] Re: type class instance selection search

2007-08-01 Thread Conal Elliott
On 8/1/07, apfelmus [EMAIL PROTECTED] wrote: There are some fundamental problems/design choices for type classes in conjunction with separate compilation/modularity that need to be researched before trying anything like that. In particular, any ad-hoc Prolog, CHR or

Re: [Haskell] Re: type class instance selection search

2007-08-01 Thread Conal Elliott
On 7/31/07, jeff p [EMAIL PROTECTED] wrote: Hello, My understanding is that this sort of instance collection doesn't work together because instance selection is based only on the matching the head of an instance declaration (part after the =). I'm wondering why not use the

[Haskell] Re: type class instance selection search

2007-07-31 Thread Chung-chieh Shan
Conal Elliott [EMAIL PROTECTED] wrote in article [EMAIL PROTECTED] in gmane.comp.lang.haskell.general: I keep running into situations in which I want more powerful search in selecting type class instances. I agree that it's quite useful for instance search to backtrack, if not desirable in all

[Haskell] Re: type class instance selection search

2007-07-31 Thread Conal Elliott
Here are some other instances that could work with backward chaining: \begin{code} instance Monad m = Applicative m where pure = return (*) = ap instance (Applicative f, Monoid a) = Monoid (f a) where mempty = pure mempty mappend = liftA2 mappend instance (Applicative f, Num a) =

Re: [Haskell] Re: type class instance selection search

2007-07-31 Thread Conal Elliott
Thanks for these pointers, Ken. And belated thanks to Oleg for his reply in June. Impressive tricks! Perhaps I'm not the only person who'd prefer a more straightforward formulation of backtracking search? Cheers, - Conal On 7/31/07, Chung-chieh Shan [EMAIL PROTECTED] wrote: Conal Elliott

Re: [Haskell] Re: type class instance selection search

2007-07-31 Thread jeff p
Hello, My understanding is that this sort of instance collection doesn't work together because instance selection is based only on the matching the head of an instance declaration (part after the =). I'm wondering why not use the preconditions as well, via a Prolog-like, backward-chaining

[Haskell-cafe] Re: Type class help please

2007-05-17 Thread Adrian Hey
[EMAIL PROTECTED] wrote: Incidentally, Hugs reports the overlapping errors eagerly. It would still complain about the changed code, because the error is with instances rather with their use. Thankyou for your patience. I think I'm getting what's going on now. The flags that allow undecidable

[Haskell-cafe] Re: Type class help please

2007-05-16 Thread oleg
Adrian Hey wrote: -- Instances of GT are instances of Eq -- instance (GT map key, Eq a) = Eq (map a) where map1 == map2 = assocsAscending map1 == assocsAscending map2 ... Overlapping instances for Eq [(key, a)] arising from use of `==' at Test.hs:10:16-59 Matching

[Haskell-cafe] Re: Type class help please

2007-05-16 Thread Adrian Hey
[EMAIL PROTECTED] wrote: Adrian Hey wrote: -- Instances of GT are instances of Eq -- instance (GT map key, Eq a) = Eq (map a) where map1 == map2 = assocsAscending map1 == assocsAscending map2 ... Overlapping instances for Eq [(key, a)] arising from use of `==' at Test.hs:10:16-59

Re: [Haskell-cafe] Re: Type class help please

2007-05-16 Thread Adrian Hey
Adrian Hey wrote: [EMAIL PROTECTED] wrote: Adrian Hey wrote: -- Instances of GT are instances of Eq -- instance (GT map key, Eq a) = Eq (map a) where map1 == map2 = assocsAscending map1 == assocsAscending map2 ... Overlapping instances for Eq [(key, a)] arising from use of `=='

[Haskell-cafe] Re: Type class help please

2007-05-16 Thread oleg
Also, I suspect I'm still missing something important here, for example I don't understand why, if it overlaps for [], it doesn't overlap with other instances (like Maybe for example). Or am I just not getting the error for Maybe because ghc stops after the first error? One may think of

[Haskell] Re: Type-class overloaded functions: second-order typeclass programming with backtracking

2006-11-19 Thread oleg
Sorry, forgor the precise URLs http://pobox.com/~oleg/ftp/Haskell/poly2.hs http://pobox.com/~oleg/ftp/Haskell/poly2.txt ___ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell

[Haskell] Re: Type Class Question

2005-11-22 Thread oleg
Paul Govereau wrote: BTW, The above program is a translation of an idiomatic use of functors in ML (pardon my syntax): module A : sig type t = ... end module B : funsig(X:SHOW where t = A.t) sig bar : A.t - string end module C : SHOW where t = A.t open A open B(C) ML modules

[Haskell] Re: type class does not compile

2004-07-12 Thread oleg
Ben Yu wrote: class Rule r u u' m where apply :: r - u - m u' data And = And data Bin a b o = Bin a b o instance (Monad m, Rule r1 u u' m, Rule r2 u' u'' m) = Rule (Bin r1 r2 And) u u'' m where apply (Bin r1 r2 _) u = apply r1 u = apply r2 Ghc complains about Could not

RE: type class problem / GHC bug

2003-11-11 Thread Brandon Michael Moore
On Mon, 10 Nov 2003, Simon Peyton-Jones wrote: | Also, I tried to update and rebuild, but the makefiles seem to have the | dependencies wrong or something. I compiles THSyntax.hs by hand, then ran | into some trouble with files that needed some modules from GHCI trying | (and dying) to

RE: type class problem / GHC bug

2003-11-10 Thread Simon Peyton-Jones
A bug thank you; now fixed. Please send bug reports about GHC to [EMAIL PROTECTED], not to the Haskell mailing list. Simon | -Original Message- | From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Brandon | Michael Moore | Sent: 08 November 2003 13:20 | To: [EMAIL PROTECTED]

Re: type class problem

2003-10-01 Thread Martin Sulzmann
There's another possible fix which makes use of scoped variables. instance (RT r1 t1, RT r2 t2, TPair t t1 t2) = RT (RPair r1 r2) t where rtId (RPair r1 r2) t = RT (RPair ++ rtId r1 t1 ++ ++ rtId r2 t2 ++) where (t1::t1,t2::t2) = prj t ^^ scoped variables

Re: type class problem

2003-09-30 Thread oleg
Dean Herington wrote: Can someone explain why the following doesn't work? {-# OPTIONS -fglasgow-exts #-} class R r where rId :: r - String class (R r) = RT r t where rtId :: r - t - String data RPair r1 r2 = RPair r1 r2 instance (R r1, R r2) = R (RPair r1 r2) where rId (RPair

RE: Type class problem

2003-09-02 Thread Simon Peyton-Jones
| I'm wondering if the general method of avoiding non-termination can be | made to work in these more complex cases. | | Incidentally, the constraint solver stack overflow problem can be | turned to our advantage. The typechecker's exhausting the stack should | be considered a failure to match

RE: Type class problem

2003-09-02 Thread Simon Peyton-Jones
| b) at the moment dictionaries have the property that you can always | evaluate them using call-by-value; if they could be recursively | defined (as you suggest) that would no longer be the case | | Mind you, GHC doesn't currently take advantage of (b), so maybe it | should be

RE: Type class problem

2003-08-30 Thread Brandon Michael Moore
On 28 Aug 2003, Carl Witty wrote: On Thu, 2003-08-28 at 13:10, Brandon Michael Moore wrote: Unfortunately I don't have a useful syntatic condition on instance declarations that insures termination of typechecking. If types are restriced to products, sums, and explicit recursion, then

RE: Type class problem

2003-08-29 Thread Carl Witty
On Thu, 2003-08-28 at 13:10, Brandon Michael Moore wrote: Unfortunately I don't have a useful syntatic condition on instance declarations that insures termination of typechecking. If types are restriced to products, sums, and explicit recursion, then termination is ensured if we restrict the

RE: Type class problem

2003-08-28 Thread Brandon Michael Moore
On Fri, 22 Aug 2003, Simon Peyton-Jones wrote: Brandon writes | An application of Mu should be showable if the functor maps showable types | to showable types, so the most natural way to define the instance seemed | to be | | instance (Show a = Show (f a)) = Show (Mu f) where | show

RE: Type class problem

2003-08-22 Thread Simon Peyton-Jones
Brandon writes | An application of Mu should be showable if the functor maps showable types | to showable types, so the most natural way to define the instance seemed | to be | | instance (Show a = Show (f a)) = Show (Mu f) where | show (In x) = show x | | Of course that constraint didn't

Re: Type class problem

2003-08-17 Thread oleg
I defined type recursion and naturals as newtype Mu f = In {unIn :: f (Mu f)} data N f = S f | Z type Nat = Mu N An application of Mu should be showable if the functor maps showable types to showable types, so the most natural way to define the instance seemed to be instance (Show a =

Re: Type class problem

2003-08-17 Thread Brandon Michael Moore
On Sun, 17 Aug 2003 [EMAIL PROTECTED] wrote: I defined type recursion and naturals as newtype Mu f = In {unIn :: f (Mu f)} data N f = S f | Z type Nat = Mu N An application of Mu should be showable if the functor maps showable types to showable types, so the most natural way to

Re: type class VS struct/functor

2002-01-23 Thread Rijk-Jan van Haaften
At 13:15 2002-01-22 -0500, Hongwei Xi wrote: ... In Haskell, I guess that the one implemented later is always chosen. Why can't I have two different implementations for an interface? Actually, I can't think of situations where I would desire this. Could you please give an example? Another

Re: type class VS struct/functor

2002-01-23 Thread Mike Gunter
You can also export the type without exporting the constructors. That way importers can use the type in type signatures and instance declarations while still not being able to use anything but the exported interface. E.g. instead of Module Set ( emptySet , makeSet

Re: type class VS struct/functor

2002-01-22 Thread Hongwei Xi
On Sat, 19 Jan 2002, [EUC-KR] ¾È±â¿µ wrote: I prefer Haskell style type classes because using them one can overload functions. e.g. \begin{code} class Container a where celem :: Eq b = b - a b - Bool cmap :: (Eq b, Eq c) = (b-c) - a b - a c data MyList a = MyList [a] deriving Show

[Fwd: Re: type class VS struct/functor]

2002-01-18 Thread Ahn Ki-yung
Hmm ... How do you solve this in Haskell ? Original Message Subject: Re: type class VS struct/functor Date: Sat, 19 Jan 2002 01:34:32 GMT From: [EMAIL PROTECTED] (Neelakantan Krishnaswami) Reply-To: [EMAIL PROTECTED] Organization: ATT Broadband Newsgroups: comp.lang.functional

Re: Type class inference trouble

2001-02-19 Thread Lars Lundgren
On Sat, 17 Feb 2001, Ken Shan wrote: On 2001-02-16T09:52:41+0100, Lars Lundgren wrote: This is ad hoc overloading, and IMHO bad style, at least in haskell. As I understand it, haskell type classes were never intended to support this. Well, whether this is ad hoc overloading depends on

Re: Type class inference trouble

2001-02-16 Thread Ken Shan
On 2001-02-16T07:56:42+, Marcin 'Qrczak' Kowalczyk wrote: test2 = apply [int 3] (apply [(+)::Int-Int-Int] [int 5]) The monomorphism restriction bites again. A variable binding without a type signature is monomorphic... But, but, but... The type *is* monomorphic, in the sense that it

Re: Type class inference trouble

2001-02-15 Thread Dylan Thurston
On Thu, Feb 15, 2001 at 02:37:09PM -0500, Ken Shan wrote: test2 = apply [int 3] (apply [(+)::Int-Int-Int] [int 5]) What's strange is that when I tried this just now, the identical line at the interpreter prompt returned the correct answer [8]. This is with Hugs from February 2000; I'm

Re: Type class inference trouble

2001-02-15 Thread Ken Shan
On 2001-02-15T21:38:54-0500, Dylan Thurston wrote: On Thu, Feb 15, 2001 at 02:37:09PM -0500, Ken Shan wrote: test2 = apply [int 3] (apply [(+)::Int-Int-Int] [int 5]) What's strange is that when I tried this just now, the identical line at the interpreter prompt returned the correct

Re: Type class inference trouble

2001-02-15 Thread Marcin 'Qrczak' Kowalczyk
Thu, 15 Feb 2001 21:08:13 -0500, Dylan Thurston [EMAIL PROTECTED] pisze: On Thu, Feb 15, 2001 at 02:37:09PM -0500, Ken Shan wrote: test2 = apply [int 3] (apply [(+)::Int-Int-Int] [int 5]) What's strange is that when I tried this just now, the identical line at the interpreter prompt

Re: type class

2000-10-11 Thread Zhanyong Wan
Hi Mark, Thanks for the references you provided! Mark P Jones wrote: My instinct (which perhaps somebody will prove incorrect) is that this will not help. Suppose, for example, that you needed to unify ([a],[b]) with f c as part of the type inference process. How would you solve this

RE: type class

2000-10-09 Thread Mark P Jones
Hi Zhanyong, | In Haskell, instances of a type class can only be well-formed type | constructors ... | Note there is no type constructor abstraction. | | In practice, I found this rule too restrictive. There are good reasons for the restrictions that were alluded to in my constructor classes

Re: type class

2000-10-08 Thread Dana Harrington
Simon Peyton-Jones [EMAIL PROTECTED] writes: | How about extending TC with a branch for abstraction: | | TC ::= ... | | /\a. TC -- abstraction | | This is too powerful and will get out of control -- we surely | don't want to give TC the full power of lambda-calculus. So let's impose a |

RE: type class

2000-10-02 Thread Simon Peyton-Jones
| How about extending TC with a branch for abstraction: | | TC ::= ... | | /\a. TC -- abstraction | | This is too powerful and will get out of control -- we surely | don't want to give TC the full power of lambda-calculus. So let's impose a | restriction: in /\a.TC, a must occur free in

Re: type class

2000-10-02 Thread Carl R. Witty
Simon Peyton-Jones [EMAIL PROTECTED] writes: | How about extending TC with a branch for abstraction: | | TC ::= ... | | /\a. TC -- abstraction | | This is too powerful and will get out of control -- we surely | don't want to give TC the full power of lambda-calculus. So let's