Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable casper #9

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Notes
  • Loading branch information
jonascarpay committed Mar 14, 2022
commit 57690a4e75016bdb78433e176db586d20ec6a8eb
26 changes: 22 additions & 4 deletions src/Lib.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
{-

TODOs

CasperT should maintain a cache of UUIDs/hashes to TVars of cachable things

Transactions should be able to safely populate and read from the cache

There should be a way to evict things from the cache that are not used by any transaction
Note that a transaction could load something into the cache, be retried, and on the second run not use the thing that it loaded into the cache on the first run

Garbage collection

-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
@@ -12,6 +26,7 @@
module Lib where

import Control.Monad
import Control.Monad.IO.Class (MonadIO)
import Control.Monad.Identity (Identity)
import Data.Aeson (FromJSON, ToJSON)
import qualified Data.Aeson as Aeson
@@ -20,8 +35,6 @@ import qualified Data.ByteString.Lazy as BL
import Data.Kind (Type)
import GHC.Generics

data Graph root = Graph

newtype Transaction (mut :: Type -> Type) (imm :: Type -> Type) a = Transaction (Identity a)
deriving (Functor, Monad, Applicative)

@@ -61,12 +74,17 @@ deriving via (WrapAeson mut imm Int) instance Content mut imm Int
newtype WrapCereal mut imm a = WrapCereal {unWrapCereal :: a}

newtype CasperT s root m a = CasperT (m a)
deriving (Functor, Monad, Applicative)
deriving (Functor, Monad, Applicative, MonadIO)

loadStore :: FilePath -> (forall s. CasperT s root m a) -> m a
loadStore _ _ = undefined

transact :: (forall mut imm. root mut imm -> Transaction mut imm a) -> CasperT s root IO a
transact ::
( forall mut imm.
root mut imm ->
Transaction mut imm a
) ->
CasperT s root IO a
transact _ = undefined

localRoot ::
42 changes: 41 additions & 1 deletion src/Use.hs
Original file line number Diff line number Diff line change
@@ -8,13 +8,14 @@

module Use where

import Control.Monad.IO.Class (liftIO)
import Data.Kind (Type)
import GHC.Generics (Generic)
import Lib

data Root mut imm = Root (mut (Foo mut imm)) (mut (Foo mut imm))

data Foo mut (imm :: Type -> Type) = Foo
data Foo mut imm = Foo
{ mi :: mut Int,
mli :: mut [Int],
lmi :: [mut Int],
@@ -24,6 +25,42 @@ data Foo mut (imm :: Type -> Type) = Foo
}
deriving (Generic)

data Dataset i = Dataset ([i (Datapoint i)])
deriving (Generic)

instance Content m i (Dataset i)

data Datapoint i = DataPoint (i Int)

{-
t1 = transaction:
add set_A
add datapoint_A_A
t2 = transaction:
add set_B
add datapoint_B_A
delete set_A
t3 = transaction:
modify set_A
add datapoint_A_B

-}

-- Foo Loc Ref' ===> Foo Loc (Ref s)

-- root
-- models
-- model_A

-- root
-- datasets
-- set_A
-- datapoint_A_A
-- datapoint_A_B
-- set_B
-- datapoint_B_A
-- datapoint_B_B

instance Content mut imm (Foo mut imm)

someFunc :: IO ()
@@ -33,4 +70,7 @@ someFunc =
foo1 <- readMut l
foo2 <- readMut (rec foo1)
readMut (mi foo1)
localRoot (\(Root l r) -> rec <$> readMut l) $ do
liftIO $ putStrLn "Changed root"
pure ()
pure ()