Skip to content

Instantly share code, notes, and snippets.

View chessai's full-sized avatar

chessai chessai

View GitHub Profile
tryAll :: IO a -> IO (Either SomeException a)
tryAll = try
forkIO_ :: IO () -> IO ()
forkIO_ x = forkIO x >> pure ()
foldCommuteIO :: forall t m a. (Foldable t, Monoid m) => (a -> IO m) -> t a -> IO m
foldCommuteIO f xs = do
var <- newEmptyMVar
total <- foldlM (\ !n a -> forkIO_ ( tryAll (f a) >>= putMVar var) >> pure (n + 1)) 0 xs
[nix-shell:~/development/nixpkgs]$ nix repl default.nix
Welcome to Nix version 2.0.4. Type :? for help.
Loading 'default.nix'...
Added 9659 variables.
nix-repl> :b haskell.compiler.ghcLinear
these derivations will be built:
/nix/store/pifcl83nn43wkvsdwg1k4m089g44jqvl-hscolour-1.24.4.drv
/nix/store/77psczhb9v2j3k2av0pj52vc886v86xm-hscolour-1.24.4.drv
data Ordered a = Empty | Decreasing a | Increasing a
inc :: Ordered a -> Bool
inc (Decreasing _) = False
inc _ = True
dec :: Ordered a -> Bool
dec (Increasing _) = False
dec _ = True
@chessai
chessai / haddock.sh
Created October 25, 2018 22:03
Sometimes haddocks fail to build, even when your package builds. This script will build and upload the haddocks for you, without needing to re-upload the package or do some weird revision stuff
#!/bin/sh
set -e
dir=$(mktemp -d dist-new-docs.XXXXXX)
trap 'rm -r "$dir"' EXIT
cabal new-haddock --builddir="$dir" --haddock-for-hackage --haddock-option=--hyperlinked-source
# Starting with cabal 2.0, `--publish` is needed for uploading to non-candidate releases
cabal upload --publish -d $dir/*-docs.tar.gz
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE MagicHash #-}
module Strict (idInt, idIntCon) where
import GHC.Types
idIntCon :: Int -> Int
idIntCon (I# x) = (I# x)
@chessai
chessai / overwrite.hs
Created October 20, 2018 00:44
Overwrite.hs
hPutMutableByteArray#
:: SIO.Handle
-> MutableByteArray# RealWorld -- ^ Invariant MUST BE PINNED
-> Int#
-> State# RealWorld
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
-- | Conversion between unlifted and lifted datatypes
module Packed.Levity
( -- * Types
Rep
, Levity(..)
{ rev # The Git revision of nixpkgs to fetch
, sha256 # The SHA256 hash of the unpacked archive
}:
builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
inherit sha256;
}
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <string>
#include <stdio.h>
#include <cstring>
int main ()
{
std::ifstream in("infile.txt");
-- Copyright (c) 2014, Ryan Trinkle
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- * Redistributions of source code must retain the above copyright notice, this
-- list of conditions and the following disclaimer.
--
-- * Redistributions in binary form must reproduce the above copyright notice,