This now lives on GitHub: https://github.com/friedbrice/runhs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DerivingVia #-} | |
-- | Basic memoization. | |
-- | |
-- Functions yielded by 'memoize' and 'memoizeRec' may continue to allocate | |
-- memory without bound as long as they remain in scope. That is, you can keep | |
-- them around in a single short-lived thread, such as responding to an HTTP | |
-- request, but if kept at top-level will cause memory leaks. Use 'runMemRec' | |
-- to free memory as soon as the result is computed (i.e. forced). | |
module Memoize (Mem, memoize, MemRec, memoizeRec, runMemRec) where |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Semigroup | |
data Fib = | |
Fib Integer Integer Integer | |
instance Semigroup Fib where | |
Fib a1 b1 c1 <> Fib a2 b2 c2 = | |
Fib (a1*a2 + b1*b2) (a1*b2 + b1*c2) (b1*b2 + c1*c2) | |
stimes = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# iterm_open_with - open a URL, file from CWD, full path, or path with linenumber in default app or Sublime Text if text file | |
# For usage with iTerm2: | |
# In iTerm's Preferences > Profiles > Default > Advanced > Semantic History, | |
# choose "Run command..." and enter "/your/path/to/iterm_open_with \5 \1 \2". | |
# Usage: iterm_open_with $(pwd) filename [linenumber] | |
# $(pwd) = current working directory (either use `pwd` or $PWD) | |
# filename = filename to open | |
# lineno = line number | |
pwd=$1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class Visitor { | |
/** Shape | |
* | |
* We wish to define a data type with exactly two variants: Circle and Rectangle. | |
* | |
* In particular, we do not want Shape to be open to extension by | |
* new kinds of variants (as would be the case with an abstract class). | |
* The reason we do not want the variants of Shape to be open to extension | |
* is because this will grant us the ability to extend the operations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ExplicitForAll #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE FunctionalDependencies #-} | |
{-# LANGUAGE NoStarIsType #-} | |
{-# LANGUAGE PolyKinds #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
module Main where |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This is some boilerplate code, don't worry about it. | |
{-# OPTIONS_GHC -fwarn-incomplete-patterns #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
main = return () | |
-- ** Start here for Interlude 1. ** | |
-- I. Types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Address = { | |
street: string | |
zipCode: string | |
} | |
type Contact = { | |
name: string | |
phoneNumber: string | |
email: string | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DataKinds, KindSignatures, GADTs, TypeOperators #-} | |
module BlockMatrix where | |
import GHC.TypeLits | |
data Block (n :: Nat) (m :: Nat) a where | |
Number :: a -> Block 1 1 a | |
Fourths :: Block n1 m1 a -> Block n1 m2 a -> Block n2 m1 a -> Block n2 m2 a -> Block (n1 + n2) (m1 + m2) a | |
Vhalves :: Block n m1 a -> Block n m2 a -> Block n (m1 + m2) a | |
Hhalves :: Block n1 m a -> Block n2 m a -> Block (n1 + n2) m a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%YAML 1.2 | |
--- | |
# See http://www.sublimetext.com/docs/3/syntax.html | |
name: Haskell (Cabal) | |
file_extensions: | |
- cabal | |
scope: source.cabal | |
variables: | |
ident: '[a-zA-Z\_][a-zA-Z\_\-0-9]*' |