Skip to content

Instantly share code, notes, and snippets.

@xgrommx
xgrommx / frequency.hs
Created August 30, 2017 13:01 — forked from ybigus/frequency.hs
frequency
count:: Int -> [Int] -> Int
count x arr = length $ filter (\i -> i == x) arr
freq:: [Int] -> [Int] -> [(Int, Int)]
freq [] _ = []
freq (x:xs) acc = [(x, count x acc + 1)] ++ freq xs (x: acc)
example:: [(Int, Int)]
example = freq [1,2,1,2,4,2,1] []
@xgrommx
xgrommx / README.md
Created August 27, 2017 01:42 — forked from ujihisa/README.md

ISeq (Stack Machine)

data Inst = IPlus | IMult | ICall String | IPush Int |
  ILt | INeg | IZeroJump Int | IJump Int | ILabel Int |
  ISetLocal String | IGetLocal String deriving (Show, Eq)
  • IPlus
  • IMult
  • ILt
  • Consumes 2 values and stores the result of plus/mult/less-than by the two values

Stephen Diehl (@smdiehl )

Since I wrote these slides for a little user group talk I gave two years ago they have become a surprisingly popular reference. I decided to actually turn them into a proper skimmable reference for intermediate and advanced level Haskell topics that don't necessarily have great coverage or that tend be somewhat opaque as to where to get going, and then aggregate a bunch of the best external resources for diving into those subjects with more depth. Hopefully it still captures the "no bullshit brain dump" style that seemed to be liked.

The source for all code is available here. If there are any errors or you think of a more illustrative example feel free to submit a pull request.

@xgrommx
xgrommx / Either-hof.agda
Created April 14, 2017 00:42 — forked from madidier/Either-hof.agda
Sum type encoding and catamorphism of "Either" in various languages and approaches
-- I haven't been able to actually run the program (broken archlinux packages), but it typechecks
open import Data.String
open import Function
open import IO.Primitive
Either : Set → Set → Set₁
Either l r = {a : Set} → (l → a) → (r → a) → a
Left : { l r : Set } → l → Either l r
@xgrommx
xgrommx / Pascal.hs
Created April 11, 2017 07:15 — forked from queertypes/Pascal.hs
Pascal's triangle in Haskell
import Control.Applicative ((<$>))
center :: String -> Int -> String
center s n = spaces ++ s ++ spaces
where spaces = replicate ((n - length s) `div` 2) ' '
-- http://www.haskell.org/haskellwiki/Blow_your_mind, Ctrl-F "pascal"
pascal :: [[Int]]
pascal = iterate (\row -> zipWith (+) ([0] ++ row) (row ++ [0])) [1]
@xgrommx
xgrommx / _FP reading lists.md
Created March 9, 2017 21:11 — forked from danidiaz/_FP reading lists.md
assorted reading lists

A series of reading lists mostly related to functional programming.

@xgrommx
xgrommx / t.hs
Created March 2, 2017 18:13 — forked from oisdk/t.hs
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
import Data.Functor.Foldable hiding (Foldable)
import qualified Data.Functor.Foldable as Functor
import Data.Traversable
import qualified Data.Map as Map
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE FlexibleContexts #-}
module Data.Functor.Foldable.Monadic
( cataM
, anaM
, futuM
) where
import Protolude