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

Keean Schupke k.schupke at imperial.ac.uk
Thu Mar 31 10:14:57 EST 2005


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 <rherk at cs.uu.nl>
> Date:
> Thu, 31 Mar 2005 16:49:07 +0200
> To:
> glasgow-haskell-users at haskell.org
>
> To:
> glasgow-haskell-users at haskell.org
>
> Return-Path:
> <glasgow-haskell-users-bounces at haskell.org>
> X-Original-To:
> rherk at students.cs.uu.nl
> Delivered-To:
> rherk at 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 
> <rherk at students.cs.uu.nl>; 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 
> <rherk at students.cs.uu.nl>; 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 at 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 at haskell.org
> Delivered-To:
> glasgow-haskell-users at 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 
> <glasgow-haskell-users at haskell.org>; 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 at 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 at cs.uu.nl> <42443712.3080804 at imperial.ac.uk> 
> <424464A0.6090805 at cs.uu.nl> <42446C75.4090500 at imperial.ac.uk> 
> <424488C9.9010301 at cs.uu.nl> <42449A15.6080003 at imperial.ac.uk>
> In-Reply-To:
> <42449A15.6080003 at 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 at haskell.org
> X-Mailman-Version:
> 2.1.5
> Precedence:
> list
> List-Id:
> The Glasgow Haskell Users Mailing List 
> <glasgow-haskell-users.haskell.org>
> List-Unsubscribe:
> <http://www.haskell.org/mailman/listinfo/glasgow-haskell-users>, 
> <mailto:glasgow-haskell-users-request at haskell.org?subject=unsubscribe>
> List-Archive:
> <http://www.haskell.org//pipermail/glasgow-haskell-users>
> List-Post:
> <mailto:glasgow-haskell-users at haskell.org>
> List-Help:
> <mailto:glasgow-haskell-users-request at haskell.org?subject=help>
> List-Subscribe:
> <http://www.haskell.org/mailman/listinfo/glasgow-haskell-users>, 
> <mailto:glasgow-haskell-users-request at haskell.org?subject=subscribe>
> Sender:
> glasgow-haskell-users-bounces at haskell.org
> Errors-To:
> glasgow-haskell-users-bounces at 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.



More information about the Glasgow-haskell-users mailing list