From af1b2b877b612d6125bea9f00bdd5c44fe3fe850 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Fri, 23 Mar 2018 21:25:09 -0700 Subject: [PATCH] Add knightDeltas.hs --- dotfiles/lib/bin/knightDeltas.hs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 dotfiles/lib/bin/knightDeltas.hs diff --git a/dotfiles/lib/bin/knightDeltas.hs b/dotfiles/lib/bin/knightDeltas.hs new file mode 100755 index 00000000..196d53d3 --- /dev/null +++ b/dotfiles/lib/bin/knightDeltas.hs @@ -0,0 +1,22 @@ +#!/usr/bin/env run_haskell_stack.sh + +import Data.Bifunctor +import Data.Tuple + +knightDeltasSimple = + applyAll [swap] (1, 2) + >>= applyAll [first negate, second negate, bimapBoth negate] + where applyAll fns v = map ($ v) $ id:fns + bimapBoth fn = bimap fn fn + +knightDeltas = applyInStages [(1, 2)] + [ [swap] + , [bimapBoth (* 2)] + , [first negate, second negate, bimapBoth negate] + ] + where applyAll fns v = map ($ v) $ id:fns + applyAllToValues values fns = values >>= applyAll fns + applyInStages = foldl applyAllToValues + bimapBoth fn = bimap fn fn + +main = print knightDeltas