Skip to content

Instantly share code, notes, and snippets.

@Kiwi
Kiwi / nix-package-search
Created January 24, 2021 17:22 — forked from olejorgenb/nix-package-search
nix-package-search

Magic

It’s folklore that if you’re summing a list of numbers, then you should always use strict foldl. Is that really true though? foldr is useful for lists when the function we use is lazy in its second argument. For (+) :: Int -> Int -> Int this is tyically not the case, but in some sense that’s because Int is “too strict”. An alternative representation of numbers is to represent them inductively. If we do this, sumation can be lazy, and foldr can do things that foldl simply can’t!

First, let’s define natural numbers inductively, and say how to add them:

data Nat = Zero | OnePlus Nat deriving Show

one :: Nat
@duairc
duairc / net.nix
Last active April 16, 2024 00:28
IP address arithmetic and validation in Nix
{ lib ? null, ... }:
let
net = {
ip = {
# add :: (ip | mac | integer) -> ip -> ip
#
# Examples:
@emilypi
emilypi / ghci.conf
Last active July 9, 2021 16:49
My modest ghci.conf
-- -------------------------------------------------------------------- --
-- Default Extensions
:set -XRankNTypes
:set -XGADTs
:set -XTypeFamilies
:set -XTypeApplications
:set -XBangPatterns
:set -XMagicHash
:set -XMultiParamTypeClasses
@Nadrieril
Nadrieril / shell.nix
Last active March 17, 2024 08:03
Building LineageOS on NixOS
# I used this shell.nix to build LineageOS 13.0 for my maguro (Samsung Galaxy Nexus GSM) phone
# The build instructions for normal Linuxes are here: https://wiki.lineageos.org/devices/maguro/build
# For NixOS, follow those instructions but skip anything related to installing packages
# Detailed instructions:
# cd into an empty directory of your choice
# copy this file there
# in nix-shell:
# $ repo init -u https://github.com/LineageOS/android.git -b cm-13.0
# $ repo sync
# $ source build/envsetup.sh
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module HList where
import Prelude hiding (head, tail, zip)
@lorennorman
lorennorman / hex_grid.scad
Created December 29, 2011 17:02
learning me some openscad by playing with a hexagonal grid
module hexagon(radius)
{
circle(r=radius,$fn=6);
}
module shell(radius)
{
difference()
{
hexagon(radius*1.2); // base