Skip to content

Instantly share code, notes, and snippets.

View AndrasKovacs's full-sized avatar

András Kovács AndrasKovacs

View GitHub Profile
@AndrasKovacs
AndrasKovacs / Pigeonhole.agda
Last active January 30, 2016 19:53
Pigeonhole principle
open import Data.Nat
open import Data.Unit
open import Data.Vec
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
open import Data.Empty
open import Data.Product
import Level
module _ {α}{A : Set α} where
@AndrasKovacs
AndrasKovacs / BinNat.agda
Last active August 29, 2015 14:02
Software foundations extra Bin - Nat exercise
open import Function
open import Data.Nat
open import Relation.Binary.PropositionalEquality
open import Data.Nat.Properties.Simple
open import Data.Unit
data Bin : Set where
zero : Bin
2*n 2*n+1 : Bin → Bin
@AndrasKovacs
AndrasKovacs / BuildGraph.hs
Last active March 9, 2017 04:01
Graph building code for SO question. See link in source.
-- http://stackoverflow.com/questions/24278006/need-advice-on-optimising-haskell-data-processing/
-- http://stackoverflow.com/questions/24344440/optimising-haskell-data-processing-part-ii
-- ****************** "Normal" version *****************************
import Data.Vector (Vector)
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as BS
import qualified Data.IntSet as IS
@AndrasKovacs
AndrasKovacs / ArraySnoc.hs
Created May 6, 2014 14:00
Benchmarking primitive array snoc (GHC 7.8.2, 64 bit, -O2, -fllvm)
{-# LANGUAGE MagicHash, UnboxedTuples #-}
import Criterion.Main
import Criterion.Config
import GHC.Exts
import GHC.ST
data Array a = Array (Array# a)
snoc :: Array a -> a -> Array a
@AndrasKovacs
AndrasKovacs / Mini2048.hs
Last active July 15, 2017 12:10
2048 game clone. Has identical mechanincs to "http://gabrielecirulli.github.io/2048/" as far as I can tell.
{-
Copyright (C) 2014 András Kovács
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOF
@AndrasKovacs
AndrasKovacs / NatProps.hs
Last active August 29, 2015 13:56
Singletons + TypedHoles
{-# LANGUAGE
DataKinds, PolyKinds, TypeFamilies, TemplateHaskell,
ScopedTypeVariables, UndecidableInstances, GADTs, TypeOperators #-}
import Data.Singletons.TH
$(singletons [d|
data Nat = Zero | Succ Nat
(+) :: Nat -> Nat -> Nat
@AndrasKovacs
AndrasKovacs / WellTyped.hs
Last active August 24, 2023 10:48
Well-typed interpreter from the Idris tutorial (http://eb.host.cs.st-andrews.ac.uk/writings/idris-tutorial.pdf) in Haskell.
{-# LANGUAGE
LambdaCase, GADTs, TypeOperators, TypeFamilies, DataKinds #-}
data Type = TInt | TBool | Type :=> Type
-- Needs GHC >= 7.8
type family Interp (t :: Type) where
Interp TInt = Int
Interp TBool = Bool
Interp (a :=> b) = Interp a -> Interp b
@AndrasKovacs
AndrasKovacs / IAmNotAFiniteNumber.hs
Last active August 29, 2015 13:56
De Bruijn indexing as in "http://www.cs.ru.nl/~james/RESEARCH/haskell2004.pdf" but with statically checked finite indices.
{-# LANGUAGE
DataKinds, GADTs, TypeFamilies,
ScopedTypeVariables, LambdaCase,
TemplateHaskell, StandaloneDeriving,
DeriveFunctor, DeriveFoldable, DeriveTraversable, TypeOperators #-}
import Data.Singletons.TH
import Data.Foldable (Foldable)
import Data.Traversable (Traversable)
@AndrasKovacs
AndrasKovacs / GildedRose.hs
Last active August 29, 2015 13:56
Gilded Rose kata with lens and ADTs (of course we don't observe the original "don't change the data structure" constraint here).
{-# LANGUAGE
TemplateHaskell, LambdaCase, MultiParamTypeClasses,
FlexibleInstances, FunctionalDependencies #-}
import Control.Applicative
import Control.Lens
import Control.Lens.Extras
data Item = Simple {_sellIn :: Int, _quality :: Int, _itemName :: String}
| Conjured {_sellIn :: Int, _quality :: Int, _itemName :: String}
@AndrasKovacs
AndrasKovacs / Notes.hs
Last active August 29, 2015 13:56
Random notes.
{-# LANGUAGE
LambdaCase, DeriveFunctor, FlexibleContexts,
RankNTypes, TemplateHaskell, NoMonomorphismRestriction #-}
-- golfing the state monad with free
import Control.Monad
import Control.Monad.Free
import Control.Monad.Free.TH