Oops [Fwd: Re: Allowing duplicate instances in GHC 6.4]

Sorry, this is the compiler error I get: No instances for (KeyHasValue MyKeyVal k' v', Datasource.Tools.FakePrelude.TypeEq Float k' z, Datasource' z [MyKeyVal] [MyKeyVal] Float Int) When I am trying to do do { createJoinedDS' x x; (joined,(v::Maybe Int)) <- _dsread joined (2.0::Float); } Robert

Robert van Herk wrote:
Sorry, this is the compiler error I get:
No instances for (KeyHasValue MyKeyVal k' v', Datasource.Tools.FakePrelude.TypeEq Float k' z, Datasource' z [MyKeyVal] [MyKeyVal] Float Int) When I am trying to do
do { createJoinedDS' x x; (joined,(v::Maybe Int)) <- _dsread joined (2.0::Float); }
Robert
------------------------------------------------------------------------
Subject: Re: Allowing duplicate instances in GHC 6.4 From: Robert van Herk
Date: Thu, 31 Mar 2005 16:49:07 +0200 To: glasgow-haskell-users@haskell.org To: glasgow-haskell-users@haskell.org
Return-Path:
X-Original-To: rherk@students.cs.uu.nl Delivered-To: rherk@students.cs.uu.nl Received: from mail.students.cs.uu.nl (localhost.localdomain [127.0.0.1]) by mail.students.cs.uu.nl (Postfix) with ESMTP id 85339225D8C for ; Thu, 31 Mar 2005 16:54:12 +0200 (CEST) Received: from mail.cs.uu.nl (dusk.cs.uu.nl [131.211.80.10]) by mail.students.cs.uu.nl (Postfix) with ESMTP id 68C95225D84 for ; Thu, 31 Mar 2005 16:54:12 +0200 (CEST) Received: by mail.cs.uu.nl (Postfix) id EF0D9A35E2; Thu, 31 Mar 2005 16:54:11 +0200 (CEST) Delivered-To: rherk@cs.uu.nl Received: from mail.cs.uu.nl (localhost.localdomain [127.0.0.1]) by mail.cs.uu.nl (Postfix) with ESMTP id D9C06A35F7; Thu, 31 Mar 2005 16:54:11 +0200 (CEST) Received: from www.haskell.org (bugs.haskell.org [128.36.229.215]) by mail.cs.uu.nl (Postfix) with ESMTP id 99FA2A35E2; Thu, 31 Mar 2005 16:54:11 +0200 (CEST) Received: from haskell.cs.yale.edu (localhost.localdomain [127.0.0.1]) by www.haskell.org (Postfix) with ESMTP id 666A436825E; Thu, 31 Mar 2005 09:36:48 -0500 (EST) X-Original-To: glasgow-haskell-users@haskell.org Delivered-To: glasgow-haskell-users@haskell.org Received: from mail.cs.uu.nl (dusk.cs.uu.nl [131.211.80.10]) by www.haskell.org (Postfix) with ESMTP id 3A87D368106 for ; Thu, 31 Mar 2005 09:36:45 -0500 (EST) Received: from mail.cs.uu.nl (localhost.localdomain [127.0.0.1]) by mail.cs.uu.nl (Postfix) with ESMTP id 16C67A35F7; Thu, 31 Mar 2005 16:54:05 +0200 (CEST) Received: from [131.211.84.110] (mckroket.labs.cs.uu.nl [131.211.84.110]) by mail.cs.uu.nl (Postfix) with ESMTP id 0635AA35E2; Thu, 31 Mar 2005 16:54:05 +0200 (CEST) Message-ID: <424C0DE3.5050402@students.cs.uu.nl> User-Agent: Mozilla Thunderbird 1.0 (Macintosh/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 References: <42441324.6010804@cs.uu.nl> <42443712.3080804@imperial.ac.uk> <424464A0.6090805@cs.uu.nl> <42446C75.4090500@imperial.ac.uk> <424488C9.9010301@cs.uu.nl> <42449A15.6080003@imperial.ac.uk> In-Reply-To: <42449A15.6080003@imperial.ac.uk> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AV-Checked: ClamAV using ClamSMTP at cs.uu.nl X-BeenThere: glasgow-haskell-users@haskell.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: The Glasgow Haskell Users Mailing List List-Unsubscribe: http://www.haskell.org/mailman/listinfo/glasgow-haskell-users, mailto:glasgow-haskell-users-request@haskell.org?subject=unsubscribe List-Archive: http://www.haskell.org//pipermail/glasgow-haskell-users List-Post: mailto:glasgow-haskell-users@haskell.org List-Help: mailto:glasgow-haskell-users-request@haskell.org?subject=help List-Subscribe: http://www.haskell.org/mailman/listinfo/glasgow-haskell-users, mailto:glasgow-haskell-users-request@haskell.org?subject=subscribe Sender: glasgow-haskell-users-bounces@haskell.org Errors-To: glasgow-haskell-users-bounces@haskell.org X-AV-Checked: ClamAV using ClamSMTP at cs.uu.nl X-AV-Checked: ClamAV using ClamSMTP at students.cs.uu.nl X-Spam-Checker-Version: SpamAssassin 3.0.2-hvl (2004-11-16) on dawn.students.cs.uu.nl X-Spam-Status: No, score=-0.7 required=7.0 tests=AWL autolearn=ham version=3.0.2-hvl Hi Keean,
First of all, thank you for your answers. I have tried your solution using TypeEq.
instance (Datasource l k' v', TypeEq k k' z, Datasource' z l r k v) => Datasource (JoinedDS l r) k v where _dsread (JoinedDS refl refr) k = do { l <- readIORef refl; r <- readIORef refr; (z,l,r,v) <- _dsread' (l,r) k; writeIORef refl l; writeIORef refr r; return (JoinedDS refl refr, v); }
class Datasource' z l r k v | l r k -> v where
class Datasource' z l r k v | z l r k -> v where
_dsread' :: (l,r) -> k -> IO (z,l,r,Maybe v) _dswrite' :: (l,r) -> k -> v -> IO (z,l,r) instance Datasource l k v => Datasource' HTrue l r k v where _dsread' (l,r) k = do { (l,v) <- _dsread l k; return (hTrue, l, r, v); } instance Datasource r k v => Datasource' HFalse l r k v where _dsread' (l,r) k = do { (r,v) <- _dsread r k; return (hFalse, l, r, v); }
This compiles.
I cannot, however, include type z in the fundep of Datasource', since this conflicts with Datasource ds k v | ds k -> v. Furthermore, I do not understand how the key and value types of my right datasource (r k v) is bound to the instance of Datasource (JoinedDS l r) k v, since in the premisse (Datasource l k' v', TypeEq k k' z, Datasource' z l r k v), nothing is said about Datasource r k'' v''. However, I could be wrong in this, since Datasource r k v is in the premisse of instance Datasource r k v => Datsource' HFalse l r k v.
However, my problem is, that when I use this code:
do {joined <- createJoinedDS' x y; (joined,(v::Maybe Int)) <- _dsread joined (2.0::Float); }
{- | Easy constructor -} createJoinedDS :: (IORef left) -> (IORef right) -> JoinedDS left right createJoinedDS left right = JoinedDS left right createJoinedDS' :: left -> right -> IO (JoinedDS left right) createJoinedDS' l r = do { left <- newIORef l; right <- newIORef r; return (createJoinedDS left right); }
the compiler will complain:
Could not deduce (Datasource' z1 l r k v) from the context (Datasource (JoinedDS l r) k v, Datasource l k' v', TypeEq k k' z, Datasource' z l r k v) arising from use of `_dsread''
It seems to be the case that it cannot decide on the type of z.
See change above! Also note type of fundep for Datasource should now be: class Datasource s k v | s -> k v where ... Keean.

Some more fixes... Keean Schupke wrote:
Hi Keean,
First of all, thank you for your answers. I have tried your solution using TypeEq.
instance (Datasource l k' v', TypeEq k k' z, Datasource' z l r k v) => Datasource (JoinedDS l r) k v where _dsread (JoinedDS refl refr) k = do { l <- readIORef refl; r <- readIORef refr; (z,l,r,v) <- _dsread' (l,r) k; writeIORef refl l; writeIORef refr r; return (JoinedDS refl refr, v); }
_dsread (JoinedDS l r) k = _dsread' (typeEq (undefined::k') k) l r k
class Datasource' z l r k v | l r k -> v where
class Datasource' z l r k v | z l r k -> v where
_dsread' :: (l,r) -> k -> IO (z,l,r,Maybe v) _dswrite' :: (l,r) -> k -> v -> IO (z,l,r) instance Datasource l k v => Datasource' HTrue l r k v where _dsread' (l,r) k = do { (l,v) <- _dsread l k; return (hTrue, l, r, v);
The type says the return type of Datasource' is v where v is the type resturned from _dsread so: _dsread' _ (l,r) k = _dsread l k The types are determined by the instance... (I don't understand why you are trying to return hTrue???? _dsread :: s -> k -> v and for Datasource' _dsread :: z -> l -> r -> k -> v
} instance Datasource r k v => Datasource' HFalse l r k v where _dsread' (l,r) k = do { (r,v) <- _dsread r k; return (hFalse, l, r, v); }
This compiles.
I cannot, however, include type z in the fundep of Datasource', since this conflicts with Datasource ds k v | ds k -> v. Furthermore, I do not understand how the key and value types of my right datasource (r k v) is bound to the instance of Datasource (JoinedDS l r) k v, since in the premisse (Datasource l k' v', TypeEq k k' z, Datasource' z l r k v), nothing is said about Datasource r k'' v''. However, I could be wrong in this, since Datasource r k v is in the premisse of instance Datasource r k v => Datsource' HFalse l r k v.
However, my problem is, that when I use this code:
do {joined <- createJoinedDS' x y; (joined,(v::Maybe Int)) <- _dsread joined (2.0::Float); }
{- | Easy constructor -} createJoinedDS :: (IORef left) -> (IORef right) -> JoinedDS left right createJoinedDS left right = JoinedDS left right createJoinedDS' :: left -> right -> IO (JoinedDS left right) createJoinedDS' l r = do { left <- newIORef l; right <- newIORef r; return (createJoinedDS left right); }
the compiler will complain:
Could not deduce (Datasource' z1 l r k v) from the context (Datasource (JoinedDS l r) k v, Datasource l k' v', TypeEq k k' z, Datasource' z l r k v) arising from use of `_dsread''
It seems to be the case that it cannot decide on the type of z.
See change above!
Also note type of fundep for Datasource should now be:
class Datasource s k v | s -> k v where ...
Keean.
_______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

In the case where a datasource is determined by 's' and 'k', we need to return a different type depending on sucess or failure:
data TJust t = TJust t data TNothing = TNothing
class Datasource s k v | s k -> v where dsread :: s -> k -> v instance (Datasource l k v',Datasource r k v'',Datasource' v' v'' v) => Datasource (JoinedDS l r) k v where dsread (JoinedDS l r) k = dsread' (dsread l k) (dsread r k)
class Datasource' l r v | l r -> v where dsread' :: l -> r -> v instance Datasource' TNothing TNothing TNothing where dsread' _ _ = TNothing instance Datasource' (TJust l) TNothing (TJust l) where dsread' t _ = t instance Datasource' TNothing (TJust r) (TJust r) where dsread' _ t = t instance Datasource' (TJust l) (TJust r) TNothing where dsread' _ _ = TNothing
Now all you need to do is arrange for individual datasources to return (TJust v) if that combination of source and key exist and TNothing if they dont. Something like:
instance Datasource Source1 Key1 (TJust Value1) instance Datasource Source1 Key2 TNothing
instance Datasource Source2 Key1 TNothing instance Datasource Source2 Key2 (TJust Value2)
This is a simple implementation, using TypeEq, you can generically reject with TNothing all datasource instances not specifically defined. Keean.
Hi Keean,
First of all, thank you for your answers. I have tried your solution using TypeEq.
instance (Datasource l k' v', TypeEq k k' z, Datasource' z l r k v) => Datasource (JoinedDS l r) k v where _dsread (JoinedDS refl refr) k = do { l <- readIORef refl; r <- readIORef refr; (z,l,r,v) <- _dsread' (l,r) k; writeIORef refl l; writeIORef refr r; return (JoinedDS refl refr, v); }
class Datasource' z l r k v | l r k -> v where _dsread' :: (l,r) -> k -> IO (z,l,r,Maybe v) _dswrite' :: (l,r) -> k -> v -> IO (z,l,r) instance Datasource l k v => Datasource' HTrue l r k v where _dsread' (l,r) k = do { (l,v) <- _dsread l k; return (hTrue, l, r, v); } instance Datasource r k v => Datasource' HFalse l r k v where _dsread' (l,r) k = do { (r,v) <- _dsread r k; return (hFalse, l, r, v); }
This compiles.
I cannot, however, include type z in the fundep of Datasource', since this conflicts with Datasource ds k v | ds k -> v. Furthermore, I do not understand how the key and value types of my right datasource (r k v) is bound to the instance of Datasource (JoinedDS l r) k v, since in the premisse (Datasource l k' v', TypeEq k k' z, Datasource' z l r k v), nothing is said about Datasource r k'' v''. However, I could be wrong in this, since Datasource r k v is in the premisse of instance Datasource r k v => Datsource' HFalse l r k v.
However, my problem is, that when I use this code:
do {joined <- createJoinedDS' x y; (joined,(v::Maybe Int)) <- _dsread joined (2.0::Float); }
{- | Easy constructor -} createJoinedDS :: (IORef left) -> (IORef right) -> JoinedDS left right createJoinedDS left right = JoinedDS left right createJoinedDS' :: left -> right -> IO (JoinedDS left right) createJoinedDS' l r = do { left <- newIORef l; right <- newIORef r; return (createJoinedDS left right); }
the compiler will complain:
Could not deduce (Datasource' z1 l r k v) from the context (Datasource (JoinedDS l r) k v, Datasource l k' v', TypeEq k k' z, Datasource' z l r k v) arising from use of `_dsread''
It seems to be the case that it cannot decide on the type of z.
Would you know how to solve this?
Regards,
Robert
_______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
participants (2)
-
Keean Schupke
-
Robert van Herk