Skip to content

Instantly share code, notes, and snippets.

@chansey97
chansey97 / Crush.hs
Last active March 3, 2021 16:46
Implement cursh by Foldable.
module Crush(
AST(..)
, crush
, crushMap
, crushMapM
-- debugging
, buildAst
, printAst
) where
@chansey97
chansey97 / PCP.hs
Last active March 3, 2021 16:46
Solve PCP by BFS.
module PCP where
import Data.List
import Data.Tree
-- breadth-first traversal
levelf :: Forest a -> [[a]]
levelf = unfoldr f
where f [] = Nothing
f xs = Just (map rootLabel xs, concat $ map subForest xs)
@chansey97
chansey97 / ctfp-14.3.6-correct-solution.hs
Created November 27, 2019 08:23
ctfp-14.3.6-correct-solution
{-# LANGUAGE DeriveFunctor, TypeFamilies #-}
module Main where
data Pair a = Pair a a
deriving (Eq)
getFst :: Pair a -> a
getFst (Pair x1 _) = x1
@chansey97
chansey97 / ctfp-14.3.6-wrong-solution.hs
Created November 27, 2019 08:21
ctfp-14.3.6-wrong-solution
{-# LANGUAGE DeriveFunctor, TypeFamilies #-}
module Main where
data Pair a = Pair a a
deriving (Eq)
getFst :: Pair a -> a
getFst (Pair x1 _) = x1