GhostCell (pt2)
An attempt that "typechecks"
module Main where
import Control.Monad.ST
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector as V
newtype BrandedVector s a = BrandedVector (VM.MVector s a)
newtype BrandedIndex s = BrandedIndex Int
-- newBrandedVector :: V.Vector a -> ST (VM.
pushBack :: ST s (BrandedVector s a) -> a
-> ST s (BrandedVector s a, BrandedIndex)
pushBack prevVec val = do
BrandedVector bv <- prevVec
let len = VM.length bv
bv' <- VM.unsafeGrow bv 1
VM.unsafeWrite bv' len val
return (BrandedVector bv', BrandedIndex len)
main :: IO ()
main = putStrLn "Hello, Haskell!"
- Might need to look into linear types in Haskell
- Custom rank 2 type
{-# LANGUAGE RankNTypes #-}
newtype BrandedList s a = BrandedList [a] deriving (Show)
runOp :: [a] -> (forall s. BrandedList s a -> b) -> b
runOp v f = f $ BrandedList v
Links: