Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE RankNTypes #-}
import Control.Monad (join)
sendBoth
:: (Monad m, Applicative n)
=> (forall a. a -> m ())
-> (forall a. m a -> n a)
-> (forall a. n a -> m a)
-> m a
@nuttycom
nuttycom / return_borrow_failure.rs
Created July 29, 2020 22:41
Error in returning from a function due to a borrowed value.
error[E0515]: cannot return value referencing local variable `stmt_blocks`
--> zcash_client_sqlite/src/chain.rs:200:9
|
194 | let iter = stmt_blocks.query_map(&[from_height.0], |row| {
| ----------- `stmt_blocks` is borrowed here
...
200 | / Ok(Box::new({
201 | | iter.map(|cbr_result| {
202 | | let cbr = cbr_result.map_err(Error::from)?;
203 | | let block: CompactBlock = parse_from_bytes(&cbr.data).map_err(Error::from)?;
@nuttycom
nuttycom / config.nix
Last active April 10, 2020 18:13
Basic Haskell-development-oriented config.nix
let
rev = "d5291756487d70bc336e33512a9baf9fa1788faf";
#nvimrev = "9842c4b1076a2f54de5e9a81fd91b2b91b1d051e";
pkgs = import (builtins.fetchTarball { url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz"; }) {};
#nvimpkgs = import (builtins.fetchTarball { url = "https://github.com/NixOS/nixpkgs/archive/${nvimrev}.tar.gz"; }) {};
custom-hasktags = pkgs.fetchFromGitHub {
owner = "MarcWeber";
repo = "hasktags";
nuttycom@summer:~/ λ sh <(curl https://nixos.org/nix/install) --no-daemon
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2472 100 2472 0 0 3994 0 --:--:-- --:--:-- --:--:-- 3993
downloading Nix 2.1.3 binary tarball for x86_64-darwin from 'https://nixos.org/releases/nix/nix-2.1.3/nix-2.1.3-x86_64-darwin.tar.bz2' to '/var/folders/vx/n5_b_39s6qj6tgvh2m82r8v00000gn/T/nix-binary-tarball-unpack.XXXXXXXXXX.3tz9bT1l'...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 28.8M 100 28.8M 0 0 803k 0 0:00:36 0:00:36 --:--:-- 1615k
Note: a multi-user installation is possible. See https://nixos.org/nix/manual/#sect-multi-user-installation
performing a single-user installation of Nix...

Keybase proof

I hereby claim:

  • I am nuttycom on github.
  • I am nuttycom (https://keybase.io/nuttycom) on keybase.
  • I have a public key ASCTSxIwGt5VqJHLESpSmjCI6j1rMq2Ywi5ZnSi8h0Vkggo

To claim this, I am signing this object:

@nuttycom
nuttycom / Task.hs
Created February 8, 2018 06:30
"Real World"-ish recursion schemes example
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
module Dagny.Task where
@nuttycom
nuttycom / you_think_thats_bad.txt
Created September 5, 2017 23:57
Missing ascription error
[error] /Users/nuttycom/personal/scala_world-2017/sample_code/xenomorph/src/main/scala/xenomorph/Schema.scala:263: type mismatch;
[error] found : [γ$13$]xenomorph.PropSchema[O,[γ$40$]xenomorph.HCofree[[β$0$[_$1], γ$1$]xenomorph.SchemaF[P,β$0$,γ$1$],A,γ$40$],γ$13$] ~> [γ$14$]xenomorph.PropSchema[N,[γ$40$]xenomorph.HCofree[[β$0$[_$1], γ$1$]xenomorph.SchemaF[P,β$0$,γ$1$],A,γ$40$],γ$14$]
[error] (which expands to) scalaz.NaturalTransformation[[γ$13$]xenomorph.PropSchema[O,[γ$40$]xenomorph.HCofree[[β$0$[_$1], γ$1$]xenomorph.SchemaF[P,β$0$,γ$1$],A,γ$40$],γ$13$],[γ$14$]xenomorph.PropSchema[N,[γ$40$]xenomorph.HCofree[[β$0$[_$1], γ$1$]xenomorph.SchemaF[P,β$0$,γ$1$],A,γ$40$],γ$14$]]
[error] required: [γ$3$]xenomorph.PropSchema[O,[γ$2$]xenomorph.HCofree[[β$0$[_$1], γ$1$]xenomorph.SchemaF[P,β$0$,γ$1$],A,γ$2$],γ$3$] ~> G
[error] (which expands to) scalaz.NaturalTransformation[[γ$3$]xenomorph.PropSchema[O,[γ$2$]xenomorph.HCofree[[β$0$[_$1], γ$1$]xenomorph.SchemaF[P,β$0$,γ$1$],A,γ$2$],γ$3$],G]
[error] Pr
@nuttycom
nuttycom / gross.py
Created April 4, 2017 23:11
Python scoping
def foo():
done = [False];
def handle_sigint(signal, frame):
done[0] = True;
print("SIGINT received; stopping...")
signal.signal(signal.SIGINT, handle_sigint)
while not done[0]:
interface ShapeVisitor<A>
{
// The implementation of ApplyRect defines handling for the
// operation defined by this visitor in the case that the
// shape is a rectangle.
public A ApplyRect(IRectangle rect);
// The implementation of ApplyCircle defines handling for the
// operation defined by this visitor in the case that the
// shape is a circle.
@nuttycom
nuttycom / cata.out
Last active August 19, 2016 22:22
Example of encoding a sum type via catamorphism in Python
Python 3.5.2 |Anaconda custom (64-bit)| (default, Jul 2 2016, 17:53:06)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cata
>>> p = cata.DurationPeriod('a', 1)
>>> str(p)
'end_date: a, duration: 1'
>>> q = cata.DatePeriod('a', 'b')
>>> str(q)
'end_date: a, start_date: b'