Skip to content

Instantly share code, notes, and snippets.

View sgraf812's full-sized avatar

Sebastian Graf sgraf812

  • Karlsruhe, Germany
View GitHub Profile
@sgraf812
sgraf812 / PanAndZoomBehavior.cs
Last active December 25, 2015 20:18
Pan and zoom behavior for Windows Phone 7 + toolkit. No pan inertia/squish, just correct matrix math stuff.
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interactivity;
using System.Windows.Media;
using Microsoft.Phone.Controls;
namespace PhoneApp1
{
public class PanAndZoomBehavior : Behavior<FrameworkElement>
{
@sgraf812
sgraf812 / Example.java
Created December 19, 2013 13:30
MealyMachine using functionaljava for function interfaces and tuples.
// This won't really compile and is a rather ungeneralized example only to get you familiar with the syntax.
MealyMachine<State, Element, Option<Translation>> parser = MealyMachine.fromTransitions(
State.BEFORE,
when(State.BEFORE).then(lookOutForSourceLangHeader(source)),
when(State.IN_SECTION).then(lookOutForDirectHitsHeader),
when(State.IN_DIRECT_HITS).then(parseDirectHits(source)),
when(State.FINISHED).then(doNothing)
);
private enum State {
@sgraf812
sgraf812 / Suggestions.md
Last active August 29, 2015 14:16
Elm apply operator naming suggestions

Which canonical name for the applicative apply operator?

Criteria

@sgraf812
sgraf812 / Program.java
Created September 18, 2015 17:42
Solving the expression problem in Java with Object Algebras
// The structure of this document:
// 1. 'Define' the initial data type hierarchy
// (Integer expression trees with literals only initially, so rather a leaf)
// 2. Extend with an evaluation operation
// 3. Extend with a branching Add expression
// 4. Extend the evaluation operation to work on Add expressions
// 1. Define the data type hierarchy, expression trees.
// The paper's example is more fleshed out,
// this is the bare minimum.
@sgraf812
sgraf812 / Main.hs
Last active September 25, 2016 08:53
import Reverse
import Prelude hiding (reverse)
main :: IO ()
main = print $ reverse [1, 2, 3]
@sgraf812
sgraf812 / nomenclature.txt
Created August 11, 2017 21:09
GHC Core generated names nomenclature
ds = desugared?! some expression determined to be shared
$w<wrapper> = worker from a WW transform
$d<class><type> = dictionary parameter
$dm<method> = default method definition
$f<class><type> = concrete instance dictionary definition
$p<i><class> = ith dictionary selector
$c<method> = instance method definition, later to be bound to a $f?!
$trModule = module definitions
$s<fun> = ? specialization?
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
module Algebra where
@sgraf812
sgraf812 / algebra2.hs
Created February 16, 2018 10:08
SemiRing with better type inference
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
==================== Tidy Core ====================
2018-02-23 13:10:24.831160667 UTC
Result size of Tidy Core
= {terms: 763, types: 933, coercions: 17, joins: 10/34}
-- RHS size: {terms: 13, types: 16, coercions: 0, joins: 0/0}
Main.$WMkStream [InlPrag=INLINE[2]]
:: forall a s. (s -> Step s a) -> s -> Stream a
@sgraf812
sgraf812 / repro.hs
Created March 29, 2018 20:25
Reproduction for GHC ticket #8763
module Main (main) where
import System.Environment (getArgs)
import Control.Monad (when, forM_)
import GHC.ST
nop :: Monad m => a -> m ()
nop _ = return ()
{-# NOINLINE nop #-}