Skip to content

Instantly share code, notes, and snippets.

View sirlensalot's full-sized avatar

Stuart Popejoy sirlensalot

View GitHub Profile
@sirlensalot
sirlensalot / TxClassy.hs
Last active January 6, 2016 22:43
Transforming classy stuff.
-- Transforming between classy stuff.
-- | Foo is present in input and output.
data Foo = Foo
-- | Classy.
class HasFoo a where foo :: Lens' a Foo
-- | Maybe Bar is added to output type.
data Bar = Bar
@sirlensalot
sirlensalot / ComonadTree.hs
Created February 25, 2016 04:44
Tree is a comonad
λ> import Data.Tree
λ> import Control.Comonad
λ> let t = Node (1::Int) [Node 2 [Node 4 [],Node 5 []],Node 3 [Node 6 [],Node 7 []]]
λ> let draw = putStrLn . drawTree . fmap show
λ> draw t
1
|
+- 2
| |
| +- 4
@sirlensalot
sirlensalot / recover-cons.hs
Created April 14, 2016 00:30
Recover Cons in a newtype
newtype Ledger a = Ledger { _lEntries :: Seq a }
deriving (Eq,Show,Generic,Monoid)
makeLenses ''Ledger
instance Cons (Ledger a) (Ledger a) a a where
_Cons = prism (\(a,s) -> over lEntries (review _Cons . (a,)) s) $
\s -> case firstOf _Cons (view lEntries s) of
Nothing -> Left mempty
(Just (a,as)) -> Right (a,set lEntries as s)
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE GADTs #-}
module Juno.DSL
where
import qualified Data.ByteString as BS
import Control.Monad.Identity
data SigNonce nonce ident cmd = SigNonce {
_nIdent :: ident
@sirlensalot
sirlensalot / TwoNatsPseudoProxy.hs
Created May 16, 2016 20:48
Index a type with two Nats with "restricted proxy"
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE GADTs, DataKinds, PolyKinds, ScopedTypeVariables #-}
module Foo where
import GHC.TypeLits
import Data.Proxy
data Foo (a :: Nat) (b :: Nat) :: * where Foo :: Foo a b
instance (KnownNat a, KnownNat b) => Show (Foo a b) where
@sirlensalot
sirlensalot / TwoNatsExistential.hs
Created May 16, 2016 20:59
Index a type with two nats using existential constraints/proxy args
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE GADTs, DataKinds #-}
module Foo where
import GHC.TypeLits
import Data.Type.Equality
import Data.Proxy
data Foo (a :: Nat) (b :: Nat) :: * where
@sirlensalot
sirlensalot / debug-flycheck.md
Last active August 23, 2016 23:02
debug flycheck commands

in flycheck-start-command-checker, add (message "%s %s" checker args)

@sirlensalot
sirlensalot / main.pact
Created November 5, 2017 15:23
web pact test
(+ 1 2)
@sirlensalot
sirlensalot / Kadena-demo.md
Created May 17, 2018 06:24
Privacy demo on Kadena

Sample Usage: Running the payments demo with private functionality

Refer to "Entity Configuration" below for general notes on privacy configurations. This demo requires that there be 4 entities configured by the genconfs tool, which will name them "Alice", "Bob", "Carol" and "Dinesh". These would correspond to business entities on the blockchain, communicating with private messages over the blockchain. Confirm this setup with the server command.

Launch the cluster, and load the demo.yaml file.

node3> load demo/demo.yaml
status: success
data: TableCreated
@sirlensalot
sirlensalot / LensGuidelines.md
Last active June 15, 2018 02:44
Kadena Lens Guidelines

Lens Usage Guidelines for Kadena Code

The purpose of this is to enforce regularity around usage of the lens library. Lens gets a decent amount of flak for (a) horrific type errors (not much we can do with that) and (b) illegible squigglies. My issue with the squigglies is they cause OO- (or OCAML?)-style left-to-right evaluation. Thus, I'm not offended by some of the state-monad operators, as they slot into where <- would go in do notation.

But in the end, the ones I object to are really because their wordy counterparts are reasonably short. The big advantage of the squigglies in the end is not having to put parens around lens compositions,