<div>Thank you</div>
<div> </div>
<div>The problem here is that I cannot modify the original PP class (In fact it, in the real life, it is PersistStore). </div>
<div> </div>
<div>So I guess I am left with PP' solution.<br><br>Regards</div>
<div> </div>
<div>J-C</div>
<div> </div>
<div class="gmail_quote">On Tue, Apr 8, 2014 at 10:53 AM, Erik Hesselink <span dir="ltr"><<a href="mailto:hesselink@gmail.com" target="_blank">hesselink@gmail.com</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT:#ccc 1px solid;MARGIN:0px 0px 0px 0.8ex;PADDING-LEFT:1ex" class="gmail_quote">I've run into problems like this as well. Often you can redesign a bit<br>to fix things, although it depends on the application how to do that.<br>
Two other technical options in addition to your PP':<br><br>You can add a constraint to the 'create' function. It depends on the<br>actual semantics if this makes sense, I guess:<br><br>class PP2 m where<br>  create :: CB a => a -> m a<br>
<br>You can use ConstraintKinds [1] to add a constraint to create<br>depending on the type 'm':<br><br>type family C m a :: Constraint<br><br>class PP3 m where<br>  create :: C m a => a -> m a<br><br>This way you can choose if you want to add a constraint and which one,<br>
depending on the 'm'.<br><br>If you can solve it without any of these things, I'd probably prefer<br>that personally, though. As Tom also said, complicated type class<br>constructions often make your program more difficult to understand and<br>
maintain.<br><br>Erik<br><br>[1] <a href="http://www.haskell.org/ghc/docs/7.4.1/html/users_guide/constraint-kind.html" target="_blank">http://www.haskell.org/ghc/docs/7.4.1/html/users_guide/constraint-kind.html</a><br>
<div class="HOEnZb">
<div class="h5"><br>On Tue, Apr 8, 2014 at 10:17 AM, jean-christophe mincke<br><<a href="mailto:jeanchristophe.mincke@gmail.com">jeanchristophe.mincke@gmail.com</a>> wrote:<br>> Tom,<br>><br>> Yes of course it is simplified for clarity.<br>
><br>> Here is a modified version where fb does something (a bit more usefull)<br>><br>><br>> class PP m where<br>>     create :: a -> m a<br>><br>> data A a = A a<br>> instance PP A where<br>
>     create a = A a<br>><br>> class CB a where<br>>     fb :: a -> a<br>><br>> data B m a = B (m a)<br>> instance (PP m) => PP (B m) where<br>>     create a =  let a' = fb a<br>>                 in B (create a')<br>
><br>> class PP' m a where<br>>     create' :: a -> m a<br>><br>> instance (PP m) => PP' m a where<br>>     create' = create<br>><br>> instance (PP m, CB a) => PP' (B m) a where<br>
>     create' a = let a' = fb a<br>>                 in B (create a')<br>><br>> Actually I ran into that problem when trying to add a kind of rule engine<br>> layer above the Persistent typeclass. Given the complexity of these<br>
> typeclass, I think it is more practical to reason about a simpler form of<br>> the same problem.<br>><br>> Thanks<br>><br>> J-C<br>><br>> On Tue, Apr 8, 2014 at 9:42 AM, Tom Ellis<br>> <<a href="mailto:tom-lists-haskell-cafe-2013@jaguarpaw.co.uk">tom-lists-haskell-cafe-2013@jaguarpaw.co.uk</a>> wrote:<br>
>><br>>> On Tue, Apr 08, 2014 at 09:25:17AM +0200, jean-christophe mincke wrote:<br>>> > instance (PP m) => PP (B m) where<br>>> >     create a =  let _ = fb a<br>>> >                 in B (create a)<br>
>><br>>> Your use of 'fb' here is baffling.  Am I right in thinking you have tried<br>>> to<br>>> simplify your problem for clarity?  If so I think you have simplified too<br>>> far!<br>
>><br>>> Could you give an example where the use of 'fb' actually matters?<br>>><br>>> Tom<br>>> _______________________________________________<br>>> Haskell-Cafe mailing list<br>
>> <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>>> <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
><br>><br>><br>> _______________________________________________<br>> Haskell-Cafe mailing list<br>> <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>> <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
><br></div></div></blockquote></div><br>