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
### Keybase proof | |
I hereby claim: | |
* I am wyager on github. | |
* I am wyager (https://keybase.io/wyager) on keybase. | |
* I have a public key whose fingerprint is 4A03 3876 A021 A868 B64E 9474 3523 A9A0 071C 3DD6 | |
To claim this, I am signing this object: |
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 OverloadedStrings #-} | |
{-# LANGUAGE BangPatterns #-} | |
module Main where | |
import Data.Word | |
import Data.Array.ST | |
import Data.Array.Base (unsafeRead, unsafeWrite) | |
import Data.ByteString (ByteString) | |
import Data.ByteString.Unsafe (unsafeIndex) |
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 BangPatterns #-} | |
fib' :: Int -> Int -> Int -> Int | |
fib' !0 !a !_ = a | |
fib' !n !a !b = fib' (n-1) (b) (a+b) | |
fib :: Int -> Int | |
fib !n = fib' n 0 1 | |
main = print $ fib (1000*1000*1000) |
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
// PV :: process variable. Current measurement | |
// SP :: Setpoint. Desired measurement. | |
#include <math.h> | |
#include <stdio.h> | |
typedef struct { | |
double previous; | |
} derivative_context; |
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.Map (Map, fromList, toList, unionWith, adjust, insert) | |
import Data.List (isPrefixOf) | |
data Area = Savings | Food | FoodSavings | Investments | Expenses | Play deriving (Show, Read, Ord, Eq, Enum) | |
data Entry = Expense Area Integer | Credit Integer | Plan [(Area, Integer)] | Comment deriving (Show, Read) | |
type Savings = Map Area Integer | |
type Plan = Map Area Integer | |
noSavings = fromList [(area, 0) | area <- [Savings .. Play]] | |
defaultPlan = fromList $ (Savings, 100) : [(area, 0) | area <- [Food .. Play]] |
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 BangPatterns, ScopedTypeVariables #-} | |
import Prelude hiding (writeFile) | |
import Control.Monad.ST (ST, runST) | |
import Data.Array (Array) | |
import Data.Array.IO (IOArray) | |
import Data.Array.Unboxed (UArray) | |
import Data.Array.IArray (IArray, bounds, (!)) | |
import Data.Array.ST (STArray, runSTArray, runSTUArray) | |
import Data.Array.MArray (MArray, newArray, getBounds, freeze, readArray, writeArray) |
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
-- A first exploration into ST freeze/thaw fusion. | |
-- will.yager@gmail.com | |
{-# LANGUAGE RankNTypes, MultiParamTypeClasses, BangPatterns #-} | |
import Control.Monad.ST (ST, runST) | |
import qualified Data.Vector as V | |
import qualified Data.Vector.Mutable as M | |
import Control.Monad.Primitive (PrimMonad, PrimState) |
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 Prelude hiding (pi) | |
import Data.Ratio ((%)) | |
import Data.List(findIndex, splitAt) | |
-- Thanks to augustss on stackoverflow | |
showRational :: Int -> Rational -> String | |
showRational n r = | |
let d = round (abs r * 10^n) | |
s = show (d :: Integer) |
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
-- Monoid | |
class Ding a where | |
dong : a -> a -> a | |
-- Verified monoid | |
class Ding a => VDing a where | |
law1 : (x,y,z : a) -> dong x (dong y z) = dong (dong x y) z | |
instance Ding Nat where | |
dong = (+) |
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
-- Reaktor orbital challenge solution | |
-- Will Yager | |
import Data.Map (Map, keys, (!), fromList) | |
import Data.Set (Set, empty, notMember, insert) | |
import Data.List (find) | |
import Data.List.Split (splitOn) | |
data Cartesian = Cartesian Double Double Double deriving (Eq, Show) | |
data Polar = Polar {lat :: Double, lon :: Double, alt :: Double} deriving (Show) | |
data Line = Line {a :: Cartesian, b :: Cartesian} | |
data ID = Start | ID Int | End deriving (Eq, Ord, Show) |
OlderNewer