Skip to content

Instantly share code, notes, and snippets.

@chrisdone
chrisdone / ArrayTest.hs
Created May 22, 2019 17:15
Prana primops demo
{-# LANGUAGE MagicHash, UnboxedTuples #-}
-- | Test some of the ops for Array# and MutableArray#.
module ArrayTest where
import GHC.Exts
import GHC.Types (IO(..))
it :: IO (Char, Int, Char)
@chrisdone
chrisdone / errors.txt
Created May 22, 2019 13:00
Hasura console errors
chris@precision:~/Work/hasura/graphql-engine$ docker run --rm -it --network host --name hasura-console -v`pwd`:`pwd` -w`pwd`/console hasura/graphql-engine-console-builder:20190515 sh
# npm install
npm install
npm WARN lifecycle [email protected]~postinstall: cannot run in wd [email protected] webpack --display-error-details --config webpack/prod.config.js (wd=/home/chris/Work/hasura/graphql-engine/console)
npm WARN [email protected] requires a peer of graphql@^0.10.0 || ^0.11.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of webpack@^3.1.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of less@^2.3.1 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of graphql@^0.6.0 || ^0.7.0 || ^0.8.0-b || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 but none is installed. You must install peer de
@chrisdone
chrisdone / 1-test-suite-requirements.txt
Last active May 22, 2019 12:58
Hasura python test suite
chris@precision:~/Work/hasura/graphql-engine$ docker run --rm -it --network host --name hasura-server -v`pwd`:`pwd` -w`pwd`/server/tests-py hasura/graphql-engine-server-builder:20190507-1 sh
# pip3 install -r requirements.txt
# pytest -vv --hge-url="http://localhost:8080" --pg-url="postgres://postgres:password@localhost:6432/postgres" test_events.py
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
-- | Lists that are of finite length.
module Data.List.Finite
@chrisdone
chrisdone / limitChunks.hs
Last active May 2, 2019 09:40
Limit chunks consumed in attoparsec
{-# LANGUAGE BangPatterns #-}
{-
Limit the number of chunks used to consume a given thing.
> feeder 5 (parse (limitChunksConsumed 1 jstring)) ("\"hello world\"")
Chunk [34,104,101,108,108]
Waiting for more ...
Chunk [111,32,119,111,114]
Waiting for more ...
@chrisdone
chrisdone / 0.md
Last active April 24, 2019 08:34
Prana demonstration

This is a simple demonstration of what Prana is currently capable of doing:

  1. The script generate.sh will compile
  • ghc-prim
  • integer-gmp
  • base
  1. The binary prana-ghc acts as a replacement for regular ghc, but it also "Recompiles" and outputs .prana files
  2. The resulting "object" .prana files contain STG for each library, and they go in the PRANA_DIR directory
  3. Along with an "index" file that maps numerical references of variables/nodes/data constructors to strings like package:Module.name.
  4. That whole process takes about 15 seconds.
@chrisdone
chrisdone / 0_fib-iter.hs
Last active April 23, 2019 13:33
Fibs in Prana
fib :: Int -> Int
fib n = go 0 1 0
where
go !acc0 !acc1 !i
| i == n = acc0
| otherwise = go acc1 (acc0 + acc1) (i + 1)
it :: Int
it = fib 50

Example use:

> import Network.HTTP.Simple
> import qualified Data.ByteString.Char8 as B8
> :set -XOverloadedStrings
> import Data.String
> withWebService (responseBs "Hello!") (\port -> httpBS (fromString ("http://localhost:" ++ show port)) >>= B8.putStrLn . getResponseBody)
Hello!
>
chris@precision:~/Work/chrisdone/sandbox$ ./servant1.hs
Hello, World!
CallStack (from HasCallStack):
error, called at /home/chris/Work/chrisdone/sandbox/servant1.hs:20:30 in main:Main
Something went wrong
// GET http://127.0.0.1:3001
@chrisdone
chrisdone / 0README.md
Last active April 14, 2019 11:45
Declarative REST API DSL experimenting

Inspectable, type-safe REST API without type-level programming or TH

This approach differs from

  • Yesod
  • Servant

Instead, the following approach is used:

  1. A request can be modelled as an Applicative (a la