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
module Data.SymPair where | |
newtype SymPair a = SymPair { unSymPair :: (a, a) } deriving (Functor) | |
swapT :: (a, b) -> (b, a) | |
swapT (a, b) = (b, a) | |
instance Eq a => Eq (SymPair a) where | |
(SymPair xx) == (SymPair yy) = xx == yy || xx == swapT yy |
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
name: foo | |
-- some fields omitted for brevity | |
library foo-internal | |
hs-source-dirs: lib | |
build-depends: base | |
exposed-modules: -- everything | |
library |
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
module Alg.Generic where | |
import Alg | |
import GHC.Generics | |
instance Empty (V1 p) where | |
absurd _ = error "absurd @(V1 _)" | |
instance Unique (U1 p) 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
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE TypeOperators #-} | |
module Eliminate where | |
data Nat = Zero | Succ Nat | |
type family n + m 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
{-# language LambdaCase #-} | |
-- Note: this is just the GF(2) field. | |
instance Num Bool where | |
(+) = (/=) -- XOR | |
(*) = (&&) | |
abs = id | |
signum = id | |
fromInteger = (/= 0) . (`mod` 2) |
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
module Data.Nibble (type Nibble, pattern Nibble, mkNibble, unNibble) where | |
import Data.Function (on) | |
import Data.Word | |
newtype Nibble = MkNibble Word8 | |
deriving (Num) | |
instance Eq Nibble where (==) = (==) `on` unNibble | |
instance Ord Nibble where compare = compare `on` unNibble |
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
class Monad m => MonadNixpkgs m where | |
updateNixpkgs :: m SomeResult | |
default updateNixpkgs :: (MonadNixpkgs n, MonadTrans t, m ~ t n) => m SomeResult | |
updateNixpkgs = lift updateNixpkgs | |
-- Same thing for the other methods | |
-- Now you can write empty instances: | |
instance MonadNixpkgs m => MonadNixpkgs (ReaderT e m) |
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.Time.Clock | |
epoch :: UTCTime | |
epoch = -- whatever | |
millisecondsSinceEpoch :: IO Integer | |
millisecondsSinceEpoch = do | |
now <- getCurrentTime | |
let diff = diffUTCTime now epoch | |
let seconds = nominalDiffTimeToSeconds |
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
interface Num<T> { | |
T add(T x, T y); | |
T mult(T x, T y); | |
T abs(T x); | |
T signum(T x); | |
T fromInteger(int i); | |
default T negate(T x){ | |
return subtract(fromInteger(0), x); | |
} | |
default T subtract(T x, T y){ |
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
class TileType { | |
private: | |
const bool _walkable; | |
const char _displayChar; | |
public: | |
TileType(char displayChar, bool walkable) | |
: _displayChar(displayChar), _walkable(walkable) | |
{} | |
const bool isWalkable() { | |
return this._walkable; |