• Stars
    star
    114
  • Rank 307,967 (Top 7 %)
  • Language
    Haskell
  • License
    Other
  • Created about 6 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Build system

rock Build Status Hackage

A build system inspired by Build systems à la carte.

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

Example

{-# language FlexibleInstances #-}
{-# language GADTs #-}
{-# language StandaloneDeriving #-}
{-# language TemplateHaskell #-}

import Control.Monad.IO.Class
import Data.GADT.Compare.TH (deriveGEq)
import Data.Hashable
import Data.Some
import Data.IORef
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

instance Hashable (Query a) where
  hashWithSalt salt query =
    case query of
      A -> hashWithSalt salt (0 :: Int)
      B -> hashWithSalt salt (1 :: Int)
      C -> hashWithSalt salt (2 :: Int)
      D -> hashWithSalt salt (3 :: Int)

instance Hashable (Some Query) where
  hashWithSalt salt (Some query) = hashWithSalt salt query

rules :: Rock.Rules Query
rules key = do
  liftIO $ putStrLn $ "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
    liftIO $ putStrLn "Running"
    result <- Rock.runTask rules (Rock.fetch D)
    print result
  do
    liftIO $ putStrLn "Running with memoisation"
    memoVar <- newIORef mempty
    result <- Rock.runTask (Rock.memoise memoVar rules) (Rock.fetch D)
    liftIO $ 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

Note: Besides pure computations as shown above, the Task data type implements MonadIO, so you can lift IO actions into the Task monad by using liftIO!

Query parameters

If you need to parametrize your queries (e.g. typechecking one specific file), you can do this by adding additional arguments to your Query datatype:

data Query a where
  Parse :: FilePath -> Query AST
  Typecheck :: FilePath -> Query (Either TypeError TypedAST)

rules :: Rock.Rules Query
rules key = case key of
  Parse file -> do
    _ -- parse the file..
  Typecheck file -> do
    ast <- Rock.fetch (Parse file)
    _ -- typecheck file..

Related projects

Contributions

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

More Repositories

1

sixten

Functional programming with fewer indirections
Haskell
757
star
2

Earley

Parsing all context-free grammars using Earley's algorithm in Haskell.
Haskell
360
star
3

sixty

Dependent type checker using normalisation by evaluation
Haskell
253
star
4

Bidirectional

Haskell implementation of Dunfield and Krishnaswami's "Complete and easy bidirectional typechecking for higher-rank polymorphism"
Haskell
123
star
5

braces-be-gone

Get those pesky braces out of your face
Haskell
49
star
6

Generate-C

Embedded C code generation DSL for Haskell.
Haskell
27
star
7

dependent-hashmap

Dependent hash maps
Haskell
14
star
8

rope-utf16-splay

Thick strings optimised for indexing and updating using UTF-16 code units and row/column pairs
Haskell
14
star
9

parsix

Adventures in parser combinators
Haskell
10
star
10

region

Adventures in region inference
Haskell
8
star
11

mirrored-keyboard-layouts

Mirrored XKB layouts for one-handed typing
8
star
12

Grempa

Embedded grammar DSL and LALR parser generator
Haskell
8
star
13

navm-hs

Not a virtual machine
Haskell
6
star
14

navm

Not A Virtual Machine
Rust
6
star
15

environment-bench

Benchmarking compiler representations of variable environments
Haskell
5
star
16

incrementalism

Haskell
4
star
17

Fuse.JSON

Convert various things (JavaScript values, Objective-C objects) to and from JSON in Uno
Uno
4
star
18

oslo-haskell

Exercises
Haskell
4
star
19

packrat

Adventures in packrat parsing
Haskell
3
star
20

rope-utf16

Haskell
3
star
21

ibuild

Indexed build systems a la carte
Haskell
2
star
22

FunSharp

Learning F#, nothing to see here
F#
2
star
23

vim-svorsk

Vim for Swedes in Norway
Vim Script
2
star
24

paws

Utility for automatically pausing and resuming music at appropriate times.
C
2
star
25

fenwick

Self-balancing Fenwick trees with logarithmic time monoidal prefix sums
Haskell
2
star
26

by-value

Polymorphism without pointer indirections in C++, allowing you to store and pass subclass objects by value
C++
1
star
27

llvm-irbuilder

IRBuilder for LLVM Haskell Bindings ( Experimental )
Haskell
1
star
28

system-rea

Dad made me do it
Haskell
1
star
29

deriving-gcompare

Derive instances for GEq and GCompare from the dependent-sum package
Haskell
1
star
30

ollef.github.io

HTML
1
star
31

postgres-woobat

Haskell
1
star
32

rope-bench

Haskell
1
star
33

satire

Satisfaction
Rust
1
star