Skip to content

Instantly share code, notes, and snippets.

@justjoheinz
justjoheinz / main.lisp
Created February 10, 2024 10:32
ECS Sample with sdl2 implementation
;; https://awkravchuk.itch.io/cl-fast-ecs/devlog/622054/gamedev-in-lisp-part-1-ecs-and-metalinguistic-abstraction
(in-package #:ecs_tutorial_sdl)
(define-constant +window-width+ 800)
(define-constant +window-height+ 600)
(define-constant +repl-update-interval+ 0.3d0)
(define-constant +font-path+ (namestring (asdf:system-relative-pathname :ecs_tutorial_sdl "Resources/inconsolata.ttf"))
:test #'string=)
import Data.Vect
import Data.Fin
%default total
%access public export
data Ty: Type where
TyBool: Ty
TyInt: Ty
TyFun: Ty -> Ty -> Ty
@justjoheinz
justjoheinz / GCounter.idr
Last active September 30, 2016 13:43
GCounter.idr
module GCounter
import Data.Fin
import Data.Vect
||| GCounter is a Conflict Free Replicated Datatype.
||| For a definition, see https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type
||| It provides update, query and merge operations.
||| merge is commutative, associative and idempotent.
data GCounter : Nat -> Type where
module Sandbox
import Data.Vect
||| zip to Vectors of the same size
||| using an implicit proof
||| instead of zippy: Vect n e -> Vect n a -> Vect n (e,a)
zippy : Vect n e -> Vect m a -> {auto prf: n = m}-> Vect m (e,a)
zippy [] [] {prf} = []
zippy (x :: xs) (y :: ys) {prf = Refl} = (x, y) :: zippy xs ys
@justjoheinz
justjoheinz / sandbox.idr
Created October 22, 2015 18:57
Zippy.idr
module Sandbox
import Data.Vect
||| zip to Vectors of the same size
||| using a proof that n=m
||| instead of zippy: Vect n e -> Vect n a -> Vect n (e,a)
zippy : Vect n e -> Vect m a -> (n = m)-> Vect m (e,a)
zippy [] [] Refl = []
zippy (x :: xs) (y :: ys) Refl = (x, y) :: zippy xs ys Refl
import shapeless._
import ops._
import coproduct._
object coproducttest {
type U = Int :+: String :+: CNil
type V = Double :+: List[Int] :+: CNil
@justjoheinz
justjoheinz / test.scala
Created February 3, 2015 21:56
Dependent Values
package optionStuff
import scalaz._
import Scalaz._
object optionStuff extends App {
case class Test(a: Option[String], b: Option[String])
case object Error
implicit val errorInstance = new Monoid[Error.type] {
@justjoheinz
justjoheinz / NaturalTransformation.scala
Created October 10, 2014 15:39
Attempt to get the coproduct of natural transformations working.
trait NaturalTransformation[-F[_], +G[_]] {
self =>
def apply[A](fa: F[A]): G[A]
def compose[E[_]](f: E ~> F): E ~> G = new (E ~> G) {
def apply[A](ea: E[A]) = self(f(ea))
}
def or[H[_]](f: H ~> G): ({type f[x] = Coproduct[F, H, x]})#f ~> G =
new (({type f[x] = Coproduct[F, H, x]})#f ~> G) {
@justjoheinz
justjoheinz / gist:9217194
Created February 25, 2014 20:38
Functor / implicit conversion
package functional
trait Functor[F[_]] {
def fmap[A, B](fa: F[A])(f: A => B): F[B]
}
final class FunctorOps[F[_], A](val self: F[A])(implicit val F: Functor[F]) {
final def fmap[B](f: A => B) = F.fmap(self)(f)
}
/**
* Original source:
* [[https://gist.github.com/oxbowlakes/970717]]
*
* Modifications:
* - use scala 7.0.5
* - use toValidationNel
* - use sequenceU and traverseU instead of the lambda trick
*
* Part Zero : 10:15 Saturday Night