Skip to content

Instantly share code, notes, and snippets.

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
name: foo
-- some fields omitted for brevity
library foo-internal
hs-source-dirs: lib
build-depends: base
exposed-modules: -- everything
library
module Alg.Generic where
import Alg
import GHC.Generics
instance Empty (V1 p) where
absurd _ = error "absurd @(V1 _)"
instance Unique (U1 p) where
@Solonarv
Solonarv / Eliminate.hs
Last active September 5, 2018 20:06 — forked from alexpeits/Eliminate.hs
Haskell Peano Arithmetic
{-# LANGUAGE GADTs #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Eliminate where
data Nat = Zero | Succ Nat
type family n + m where
@Solonarv
Solonarv / bool-is-a-number.hs
Last active August 2, 2018 03:14
Silly instances.
{-# language LambdaCase #-}
-- Note: this is just the GF(2) field.
instance Num Bool where
(+) = (/=) -- XOR
(*) = (&&)
abs = id
signum = id
fromInteger = (/= 0) . (`mod` 2)
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
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)
import Data.Time.Clock
epoch :: UTCTime
epoch = -- whatever
millisecondsSinceEpoch :: IO Integer
millisecondsSinceEpoch = do
now <- getCurrentTime
let diff = diffUTCTime now epoch
let seconds = nominalDiffTimeToSeconds
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){
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;