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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / SystemF.agda
Last active June 30, 2019 21:11
Embedding of predicative polymorphic System F in Agda.
open import Function
open import Data.Nat hiding (_⊔_)
open import Data.Fin renaming (_+_ to _f+_)
open import Data.Unit
open import Relation.Binary.PropositionalEquality
open import Data.Product
open import Data.Sum
open import Data.Vec
open import Data.Vec.Properties
@AndrasKovacs
AndrasKovacs / ListMonad.agda
Last active August 29, 2015 14:05
List is a monad.
open import Data.List
open import Function
open import Relation.Binary.PropositionalEquality
open import Data.Product
open import Algebra
module LM {a}{A : Set a} = Monoid (monoid A)
infixr 5 _>>=_
_>>=_ : ∀ {a b}{A : Set a}{B : Set b} → List A → (A → List B) → List B
@AndrasKovacs
AndrasKovacs / ZipWithN.hs
Last active August 29, 2015 14:05
Polyvariadic zipWith.
{-# LANGUAGE
FlexibleInstances,
MultiParamTypeClasses,
UndecidableInstances,
IncoherentInstances, -- GHC 7.10 can do with only Overlapping
TypeFamilies #-}
class ZipWithN f t where
zipWithN' :: [f] -> t