Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Principally, you might be able to write an implementation for primitive, but not for internal, since it imposes a certain structure for your monad, which is only satisfied by the internal implementations of the IO and ST monads.</p> <p>However, my impression is that the problem is with the Data.Vector.Mutable module, whose requirements are overly strict. To use for example an IO Vector in a monad m, you principally only need an embedding of IO into m (i.e. the primitive method) and not vice versa (i.e. the internal method). If this is correct, they should try to subdivide the PrimMonad class into an embedding part and an isomorphism part, for example as follows:</p> <pre><code>-- | Class of primitive state-transformer monads class Monad m =&gt; PrimMonadEmbed m where -- | State token type type PrimState m -- | Execute a primitive operation primitive :: (State# (PrimState m) -&gt; (# State# (PrimState m), a #)) -&gt; m a class PrimMonadEmbed m =&gt; PrimMonad m where -- | Expose the internal structure of the monad internal :: m a -&gt; State# (PrimState m) -&gt; (# State# (PrimState m), a #) </code></pre> <p>This might be okay in terms of backwards compatibility since no custom instances can exist in user code. Making the requirement less strict would also make their code usable with transformed versions of the IO monad like StateT Int IO etc.</p> <p>You might try two things:</p> <ul> <li>implement a partial instance for PrimMonad which only implements the primitive method and makes internal throw an error, and see if you can use the vector library like that</li> <li>contact the authors of the vector library you are using and ask them if the above proposal is realistic...</li> </ul> <p>By the way, the following implementation of primitive should work (compare the source of STT to understand what went wrong in your code):</p> <pre><code>{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UnboxedTuples #-} module Test where import Control.Monad.Primitive import Control.Monad.ST.Trans import Control.Monad.ST.Trans.Internal instance Monad m =&gt; PrimMonad (STT s m) where type PrimState (STT s m) = s primitive f = STT (\s -&gt; case (f s) of (# s', v #) -&gt; return (STTRet s' v)) internal _ = error "no implementation of internal for STT" </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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