@hackage rock0.2.0.0

A build system for incremental, parallel, and demand-driven computations

rock Hackage

A build system inspired by Build systems à la carte and Haxl.

Used in Sixten and Sixty to achieve incremental and query driven compiler architectures.

Example

{-# language GADTs #-}
{-# language NoImplicitPrelude #-}
{-# language OverloadedStrings #-}
{-# language StandaloneDeriving #-}
{-# language TemplateHaskell #-}

import Protolude

import Data.GADT.Compare.TH (deriveGEq, deriveGCompare)
import qualified Rock

data Query a where
  A :: Query Integer
  B :: Query Integer
  C :: Query Integer
  D :: Query Integer

deriving instance Show (Query a)

deriveGEq ''Query
deriveGCompare ''Query

rules :: Rock.Rules Query
rules key = do
  putText $ "Fetching " <> show key
  case key of
    A -> pure 10
    B -> do
      a <- Rock.fetch A
      pure $ a + 20
    C -> do
      a <- Rock.fetch A
      pure $ a + 30
    D ->
      (+) <$> Rock.fetch B <*> Rock.fetch C

main :: IO ()
main = do
  do
    putText "Running"
    result <- Rock.runTask Rock.sequentially rules (Rock.fetch D)
    print result
  do
    putText "Running with memoisation"
    memoVar <- newMVar mempty
    result <-
      Rock.runTask
        Rock.sequentially
        (Rock.memoise memoVar rules)
        (Rock.fetch D)
    print result
  do
    putText "Running with memoisation using the parallel strategy"
    memoVar <- newMVar mempty
    result <-
      Rock.runTask
        Rock.inParallel
        (Rock.memoise memoVar rules)
        (Rock.fetch D)
    print result

Prints

Running
Fetching D
Fetching B
Fetching A
Fetching C
Fetching A
70
Running with memoisation
Fetching D
Fetching B
Fetching A
Fetching C
70
Running with memoisation using the parallel strategy
Fetching D
Fetching C
Fetching B
Fetching A
70

Related projects

Contributions

... are very welcome, especially in the areas of documentation, examples, testing, and benchmarking.