Restricted Types and Infinite Loops
Simon David Foster
s.d.f at btinternet.com
Mon Jan 31 15:49:20 EST 2005
Further, even if I *do* make ClassB two parameter so there should be no
ambiguity, GHC still goes into an infinite loop. This happens even with
the very latest CVS.
Plus I tried creating a proxy function for func2 with type func2' ::
Class A a b => a -> b -> String, which calls the calls func2 and placing
this in the dictionary instead, but with the same problem. I don't
understand why the resolution here should be any different to when func2
is directly within ClassA.
The system does stop going into infinite loops if I create only fully
decidable instances of ClassA, i.e. where the first parameter is
quantified as well. But I need it to be general so I can have different
contexts.
Is there anyway around this problem without actually putting func2 into
ClassA itself?
-Si.
On Thu, 2005-01-27 at 14:11 +0000, Simon David Foster wrote:
> Hi,
>
> (I've attached the full code for this problem)
>
> First I'll explain the problem description, I have two class ClassA and
> ClassB, the former has two parameters and the latter has one. The second
> parameter of ClassA is constrained by ClassB.
>
> class ClassB a where
> class ClassB b => ClassA a b where
>
> Because I wish to effectively pass the context of ClassA around, I need
> to create a pair of dictionary types (as in Restricted Data Types in
> Haskell, Hughes 99), one to represent ClassA (DictClassA) and one to
> represent ClassB (DictClassB). DictClassA also contains a term of type
> DictClassB since ClassA is a subclass of ClassB. I should then be able
> to call all the functions of ClassB via the appropriate term of
> DictClassA, like so (assuming we want to use func2);
>
> *Test> func2D (classBD (dict::DictClassA Int String)) "hello"
> "bye"
>
> So far so good, but now suppose I want Class A to have the further
> constraint
>
> class (Data (DictClassA a) b, ClassB b) => ClassA a b where
>
> (so as to make ClassA a subclass of Data)
>
> If we now try and do
>
> *Test> func2D (classBD (dict::DictClassA Int String)) "hello"
>
> We go into an infinite loop. Why? The expression still type-checks ok
> and I can't see what it is trying to do. All the functions of ClassA can
> be accessed ok, but not ClassB.
>
> *Test> funcD ((dict::DictClassA Int String)) "hello" 5
> "hello"
>
> Is it something to do with ClassB only having one parameter?
>
> I'm running GHC 20041231.
>
> -Si.
>
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
--
Simon David Foster <s.d.f at btinternet.com>
More information about the Glasgow-haskell-users
mailing list