Skip to content

Instantly share code, notes, and snippets.

View therewillbecode's full-sized avatar

Tom therewillbecode

  • Edinburgh, UK
View GitHub Profile
@therewillbecode
therewillbecode / adts.md
Last active December 11, 2017 20:39
Haskell Types

Introduction to Algebraic Data Types in Haskell

Constructor Functions vs Normal Functions

Constructor functions are the kinds of functions used to create types and values.

Constructor functions are different from normal functions in the sense that once they have had their arguments applied they are fully evaluated.

They have no equation or body so to speak. For example the value constructor Just 5 is a value just like 5 is except it has a different type.

@therewillbecode
therewillbecode / array.wat
Created April 14, 2019 17:12
Webassembly 32 bit Int Array Example
(module
(memory 1)
(func $load_num (param $index i32) (result i32)
(i32.mul (get_local $index) (i32.const 4))
i32.load
)
(func $store_num (param $index i32) (param $num i32)
(i32.mul (get_local $index) (i32.const 4))
get_local $num ;; value to store
i32.store
@therewillbecode
therewillbecode / array_ptr.wat
Last active April 18, 2019 17:00
Array with Pointer in Webassembly
(module
;; Requires that we have at least 1 page of memory available (64kb)
(import "env" "memory" (memory $mem 1))
;; Declare a global variable representing a pointer initalised to index 0 -
;; each element is a 32bit integer and thus 4 bytes wide
(global $ptr (mut i32) (i32.const 0))
(func $get_ptr (result i32)
get_global $ptr
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
module Interpreter where
import Control.Monad
@therewillbecode
therewillbecode / Poker.hs
Last active May 13, 2019 22:05
typelevel stuff
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE KindSignatures #-}
import GHC.TypeLits (Symbol)
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE KindSignatures #-}
setting SOURCE_DATE_EPOCH to timestamp 1465036472 of file authenticate-oauth-1.6/Web/Authenticate/OAuth/IO.hs
patching sources
Replace Cabal file with edited version from http://hackage.haskell.org/package/authenticate-oauth-1.6/revision/1.cabal.
compileBuildDriverPhase
setupCompileFlags: -package-db=/build/setup-package.conf.d -j4 -threaded
[1 of 1] Compiling Main ( Setup.lhs, /build/Main.o )
unpacking sources
unpacking source archive /nix/store/vnan6xar42hf2pabl7apwscqnd9w75zr-beam-core-0.7.2.3.tar.gz
source root is beam-core-0.7.2.3
setting SOURCE_DATE_EPOCH to timestamp 1549648350 of file beam-core-0.7.2.3/test/Database/Beam/Test/Schema.hs
{ system ? builtins.currentSystem, compiler ? "ghc844" } :
let
overridez = import ./nix/haskell-overridez.nix;
overlays = [
(newPkgs: oldPkgs: {
haskellPackages = oldPkgs.haskellPackages.override {
overrides = overridez.allIn ./nix;
patchFlags = [ "--binary" ];
};
let
pkgs = import <nixpkgs> {};
overridez = fetchTarball {
patchFlags = [ "--binary" ];
url = "https://github.com/adetokunbo/haskell-overridez/archive/v0.10.3.0.tar.gz";
sha256 = "1mfnjksb0n3jbbsqi7g7jd3qn0c10s5q4dg1lqx3fhqw46yvr7j7";
};
in
import overridez { inherit pkgs; }
@therewillbecode
therewillbecode / post.md
Last active November 26, 2019 16:57
Modelling the World of Blade Runner with Haskell's Type System

alt text

If you are starting your Haskell journey I implore you to focus on the type system.

Types are the roots from which your Haskell knowledge grows.

Haskell has algebraic data types. This is a fancy way of saying that we can create types which are composites of other types. Intuitively we can think of types as sets of values.