<div dir="ltr">Hi,<br>Unfortunately while this compiles it does not work correctly. For example the code:<br>data D1<br>data D2<br>class Dispatch a b where<br>   type Impl_ a b :: *<br>   runF :: a -> b -> Impl_ a b<br>instance (Show a, Impl_ D1 D2 ~ (a -> IO ())) => Dispatch D1 D2 where<br>   runF _ _ = print<br><br>compiles with the warning:<br>    No explicit associated type or default declaration for ‘Impl_’<br>    In the instance declaration for ‘Dispatch D1 D2’<br><br>But however when I run it I see that the type function does not resolve:<br>*Main> runF (undefined :: D1) (undefined :: D2)<br><br><interactive>:8:1:<br>    Couldn't match expected type ‘a0 -> IO ()’<br>                with actual type ‘Impl_ D1 D2’<br>    The type variable ‘a0’ is ambiguous<br>    In the first argument of ‘print’, namely ‘it’<br>    In a stmt of an interactive GHCi command: print it<br><br>Thanks!<br>-deech<br><br><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jan 3, 2015 at 8:59 AM, aditya siram <span dir="ltr"><<a href="mailto:aditya.siram@gmail.com" target="_blank">aditya.siram@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi,<br>That seemed to compile! I had no idea this kind of construction was even possible!<br><br>However it did spew out a bunch of warnings like:<br>"No explicit associated type or default declaration for ‘Impl’ in instance ..."<br><br>Thanks!<br>-deech<br></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 2, 2015 at 1:38 PM, Erik Hesselink <span dir="ltr"><<a href="mailto:hesselink@gmail.com" target="_blank">hesselink@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Could you do something like this?<br>
<br>
    instance (Impl D1 D2 ~ a -> IO (), C a) => Dispatch D1 D2<br>
<br>
Erik<br>
<div><div><br>
On Fri, Jan 2, 2015 at 7:59 PM, aditya siram <<a href="mailto:aditya.siram@gmail.com" target="_blank">aditya.siram@gmail.com</a>> wrote:<br>
> Hi all,<br>
> I'd like to be able to constrain an associated type.<br>
><br>
> I used to have an instance that looked like:<br>
> class Dispatch a b c | a b -> c where<br>
>    runF :: a -> b -> c<br>
> instance (C a) => Dispatch D1 D2 ( a -> IO ()) where<br>
>    runF d1 d2 = (\_ -> return ())<br>
><br>
> Since I upgraded to 7.8 from 7.5 that instance declaration is no longer<br>
> accepted is no longer accepted since it violates FD's.<br>
><br>
> I have been updating my code to use type families like so:<br>
> class Dispatch a b where<br>
>    type Impl a b :: *<br>
>    runF :: a -> b -> Impl a b<br>
> instance (C a) => Dispatch D1 D2 where<br>
>    type Impl D1 D2 = a -> IO ()<br>
>    runF d1 d2 = (\_ return ())<br>
><br>
> Unfortunately the `type Impl ...` line in the instance is rejected because<br>
> it uses `a` on the RHS.<br>
><br>
> In this one case I could just package it up into a newtype or something but<br>
> I would ideally like to be able to constrain any number of arguments like:<br>
> instance (C a, C b ... C z) => Dispatch D1 D2 where<br>
>    type Impl D1 D2 = a -> b -> ... -> z -> IO ()<br>
>    ...<br>
><br>
> This was something I could do in 7.6 (although I realize this is way safer).<br>
> How do I go about getting that constraint back?<br>
><br>
> Thanks!<br>
> -deech<br>
><br>
</div></div>> _______________________________________________<br>
> Haskell-Cafe mailing list<br>
> <a href="mailto:Haskell-Cafe@haskell.org" target="_blank">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>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>