Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you are planning to copy <code>Reifies</code> methods in a wrapper, then you could write something like this:</p> <pre><code>class R s a | s -&gt; a where r :: s -&gt; a -- etc. class R s a =&gt; RW s a where type RT s r' :: a ~ RT s =&gt; s -&gt; RT s r' = r -- etc. instance R Bool String where r = show -- etc. instance RW Bool String where type RT Bool = String -- no need to write r' = r, etc. -- &gt; :t r -- r :: R s a =&gt; s -&gt; a -- &gt; :t r' -- r' :: RW s (RT s) =&gt; s -&gt; RT s -- &gt; :t r True -- r True :: [Char] -- &gt; :t r' True -- r' True :: RT Bool -- &gt; r True -- "True" -- &gt; r' True -- "True" </code></pre> <p>so that an association between <code>a</code> and <code>RT s</code> can be expressed as an <a href="http://www.haskell.org/haskellwiki/GHC/Type_families#Equality_constraints" rel="nofollow">equality constraint</a>.</p> <hr> <p><strong>UPDATE</strong>: for 1-parametric wrapper with type family over 2-parametric class with fundep:</p> <pre><code>class R s a | s -&gt; a where r :: s -&gt; a class R' s where type RT s a r' :: (R s a, a ~ RT s a) =&gt; s -&gt; RT s a r' = r instance R Bool String where r = show instance R' Bool where type RT Bool a = a </code></pre> <p>so that:</p> <pre><code>&gt; :t r r :: R s a =&gt; s -&gt; a &gt; :t r' r' :: (R' s, R s a, RT s a ~ a) =&gt; s -&gt; RT s a &gt; :t r True r True :: [Char] &gt; :t r' True r' True :: RT Bool [Char] &gt; r True "True" &gt; r' True "True" </code></pre> <p>For example:</p> <pre><code>import qualified Data.Reflection as Reflection ( reflect ) import Data.Reflection hiding ( reflect ) class Reified s where type ReifiedType s a reflect :: (Reifies s a, a ~ ReifiedType s a) =&gt; proxy s -&gt; ReifiedType s a reflect = Reflection.reflect </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload