This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This is using a haskell comonad to find right angles between given geometrical vectors | |
-- The code is kind of overkill, but it is a cute showcase of comonads | |
-- a FocusSet. One element in Focus, and all other elements in a list. | |
data Fs a = Fs a [a] deriving (Show) | |
instance Functor Fs where | |
fmap fun (Fs k l) = Fs (fun k) (map fun l) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This is using a haskell comonad to find right angles between given geometrical vectors | |
-- The code is kind of overkill, but it is a cute showcase of comonads | |
-- a FocusSet. One element in Focus, and all other elements in a list. | |
data Fs a = Fs a [a] deriving (Show) | |
instance Functor Fs where | |
fmap fun (Fs k l) = Fs (fun k) (map fun l) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- http://blog.sigfpe.com/2006/12/evaluating-cellular-automata-is.html | |
-- The above post learned me about this neat comonad instance! :D | |
data U x = U [x] x [x] | |
right,left:: U x -> U x -- shift focus of the zipper | |
right (U a b (c:cs)) = U (b:a) c cs | |
left (U (a:as) b c) = U as a (b:c) | |
-- the zipper is a functor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html><html><head><meta charset="utf-8"/><script> | |
const isValid = raw => { | |
const words = raw.split(/\s+/) | |
// writeToBody("raw: " + raw) | |
// writeToBody("words: " + words) | |
const checker = (prevAcc, nextWord) => { | |
const acc = { set: prevAcc.set, count: prevAcc.count }; | |
if( acc.set.has(nextWord) ) { acc.count = acc.count + 1 } | |
else { acc.set.add(nextWord) } |
NewerOlder