<p dir="ltr">Hey Dmitry,</p>
<p dir="ltr">The 'Show1' class accomplishes this for types :: * -> *.</p>
<p dir="ltr"><a href="https://hackage.haskell.org/package/transformers-0.5.1.0/docs/Data-Functor-Classes.html">https://hackage.haskell.org/package/transformers-0.5.1.0/docs/Data-Functor-Classes.html</a></p>
<p dir="ltr">Then you can write: instance Show1 f => Volume f where...</p>
<br><div class="gmail_quote"><div dir="ltr">On Thu, 17 Aug. 2017, 4:02 am Jack Henahan, <<a href="mailto:jhenahan@me.com">jhenahan@me.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Some mostly unrelated thoughts:<br>
<br>
An instance head has the form `T a_1 ... a_n`, and the constraint can only<br>
apply to the `a_i`s. Consider the Show instance for<br>
pairs.<br>
<br>
instance (Show a, Show b) => Show (a, b) -- Show ((,) a b)<br>
<br>
The constraints only act on the parameters of the type.<br>
<br>
It looks like you're taking the constraint to mean "whenever I have a Showable<br>
`f String`, this is how to define a Show instance", but a constraint<br>
actually means "use this rule to make a Show instance for any `A f`, and<br>
it is an error if a Show instance for `f String` is not in scope".<br>
<br>
In the second error, you are making the strong claim that your Show<br>
instance for `A f` holds for any `f` and `a`. Even if you could trick<br>
the compiler into allowing that, I don't think it would actually express<br>
the constraint that you want it to.<br>
<br>
Is there something a Show instance gets you that a pretty-print function wouldn't?<br>
<br>
Dmitriy Matrosov <<a href="mailto:sgf.dma@gmail.com" target="_blank">sgf.dma@gmail.com</a>> writes:<br>
<br>
> Hi.<br>
><br>
> Is there a way to avoid `UndecidableInstances` in following code:<br>
><br>
>     data A f        = A {_a1 :: f String}<br>
><br>
>     instance Show (f String) => Show (A f) where<br>
><br>
> it does not compile with<br>
><br>
>     1.hs:4:10: error:<br>
>         • The constraint ‘Show (f String)’<br>
>             is no smaller than the instance head<br>
>           (Use UndecidableInstances to permit this)<br>
>         • In the instance declaration for ‘Show (A f)’<br>
><br>
> Though, initially, this was<br>
><br>
>     {-# LANGUAGE RankNTypes #-}<br>
><br>
>     data A f        = A {_a1 :: f String}<br>
><br>
>     instance forall f a. Show (f a) => Show (A f) where<br>
><br>
> which also does not compile with<br>
><br>
>     1.hs:5:10: error:<br>
>         • Variable ‘a’ occurs more often<br>
>             in the constraint ‘Show (f a)’ than in the instance head<br>
>           (Use UndecidableInstances to permit this)<br>
>         • In the instance declaration for ‘Show (A f)’<br>
><br>
> The error is different and i don't sure, that this two cases are related.<br>
><br>
> I want these instances to make a type with many records parametrized by<br>
> `Alternative` type, e.g.<br>
><br>
>     data Volume t       = Volume<br>
>                             { _volName  :: t Name<br>
>                             , _volSize  :: t Size<br>
>                             , _volPath  :: t Path<br>
>                             , _pool     :: t Pool<br>
>                             }<br>
><br>
> When i try to make instances, which require `*` type, i will end with<br>
> above cases.<br>
<br>
<br>
--<br>
Jack<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>