Skip to content

Instantly share code, notes, and snippets.

View thomashoneyman's full-sized avatar

Thomas Honeyman thomashoneyman

View GitHub Profile
@thomashoneyman
thomashoneyman / guarded.pact
Last active January 8, 2024 17:14
guard by module
(begin-tx)
(env-data { "admin": [ "admin-key" ] })
(module guards GOV
(defcap GOV () true)
(defconst GUARD_SUCCESS (create-user-guard (success)))
(defun success () true))
(define-namespace "free" guards.GUARD_SUCCESS guards.GUARD_SUCCESS)
(namespace "free")
(define-keyset "free.admin-keyset" (read-keyset "admin"))
(env-data {})
conformLegacyManifest
:: forall r
. Manifest
-> CompilerIndex
-> DependencyIndex
-> ValidateDepsError
-> Run (COMMENT + REGISTRY + STORAGE + LOG + EXCEPT String + AFF + EFFECT + r) (Tuple Manifest (Map PackageName Version))
conformLegacyManifest (Manifest manifest) currentIndex legacyIndex problem = do
let
purs :: PackageName
@thomashoneyman
thomashoneyman / Solve2.purs
Created November 9, 2023 21:36
solve with compilers
-- | A 'DependencyIndex' enriched to include the compiler versions supported by
-- | each package version as a dependency.
newtype CompilerIndex = CompilerIndex DependencyIndex
-- | Associate the compiler versions supported by each package version by
-- | inserting them as a range in the version's dependencies.
associateCompilers :: Map PackageName Metadata -> DependencyIndex -> CompilerIndex
associateCompilers allMetadata index = CompilerIndex do
foldlWithIndex
( \package prevIndex versions -> do
@thomashoneyman
thomashoneyman / refs.pact
Created January 25, 2023 01:44
Mutual reference in Pact modules
(interface gov-iface
(defun is-allowed:bool (token:string))
(defun multiplier:integer ()))
(interface token-iface
(defun supply:integer ()))
(module gov GOV
(implements gov-iface)
(defcap GOV () true)
@thomashoneyman
thomashoneyman / Cache Comparison
Last active January 3, 2023 16:00
Cache Comparison
This gist compares two implementations of a typed cache for an effects system, one in Run and one in MTL. This is a tricky effect, because:
1. The cache is typed: the key type determines the value type.
2. The cache key is polymorphic: users can define their own key types outside the module.
3. The cache is extensible: users can define multiple independent caches, each with their own implementation (such as being in-memory only, or backed by a database only, or a combination).
Both implementations preserve these properties and demonstrate how a user could implement their own key type and choose an implementation for it in their chosen effect system.
@thomashoneyman
thomashoneyman / Cache.purs
Created November 26, 2022 15:51
Typed CACHE Effect
module Registry.Effect.Cache where
import Prelude
import Data.Argonaut.Core as Argonaut.Core
import Data.Argonaut.Parser as Argonaut.Parser
import Data.Codec.Argonaut (JsonCodec)
import Data.Codec.Argonaut as CA
import Data.Const (Const(..))
import Data.Either (hush)
@thomashoneyman
thomashoneyman / chromium.nix
Created May 3, 2022 02:54
chromium on mac
{ pkgs }:
if pkgs.stdenv.isLinux then
pkgs.chromium
else
let
wrapped = pkgs.writeShellScriptBin "chromium" ''
${chromium-mac}/Chromium.app/Contents/MacOS/Chromium $@
'';
@thomashoneyman
thomashoneyman / Main.purs
Last active December 3, 2021 03:20
Emit
module Main where
import Prelude
import Halogen.Subscription (Emitter)
import Run (Run)
import Run as Run
import Type.Proxy (Proxy(..))
import Type.Row (type (+))
import Unsafe.Coerce (unsafeCoerce)
@thomashoneyman
thomashoneyman / Main.purs
Created August 24, 2021 12:36
Formless + Halogen Store part 3
-- | This example shows using Halogen Store with Formless, but the form is the only
-- | component that interacts with the global state, not the parent.
module Main where
import Prelude
import Data.Newtype (class Newtype, unwrap)
import Data.Either (Either(..))
import Data.Int as Int
import Data.Maybe (Maybe(..))
@thomashoneyman
thomashoneyman / Main.purs
Created August 24, 2021 11:24
Formless + Halogen Store, Part 2
-- | This example shows using Halogen Store with Formless, but the form is the only
-- | component that interacts with the global state, not the parent.
module Main where
import Prelude
import Data.Newtype (class Newtype, unwrap)
import Data.Either (Either(..))
import Data.Int as Int
import Data.Maybe (Maybe(..))