Skip to content

Instantly share code, notes, and snippets.

contrived value input =
let parsed = read input in -- parsed implements Read
-- read takes a String, therefore input must be String
if parsed == value -- parsed & value are same type, which implements Eq
then Just parsed
else Nothing
{-
If type bindings are still ambiguous after the function is defined, it's
preferred to leave them unresolved rather than forcing them. This keeps your
@zobar
zobar / gist:9ad4c0dab8abdbc3ba35
Last active June 3, 2016 02:55
weird movie nite
@zobar
zobar / .gitignore
Last active August 29, 2015 14:04
Ruby simulation of a full adder
.rbenv-gemsets
.yardopts
*/
@zobar
zobar / look_and_say.clj
Last active August 29, 2015 13:57
Look and say, ruby & clojure
(ns look-and-say)
(defn- consecutive [string]
(map first (re-seq #"(.)\1*" string)))
(defn- say [chars]
[(count chars) (first chars)])
(defn- get-next [string]
(apply str (mapcat say (consecutive string))))
@zobar
zobar / .gitignore
Last active December 30, 2015 16:59
Chip: composable vector operations in Ruby.
/.yardoc
/.yardopts
/coverage
/doc
@zobar
zobar / .gitignore
Last active December 28, 2015 01:29
Dimensional analysis in Scala
/project
/target
@zobar
zobar / writer.rb
Last active March 22, 2017 13:07
Writer monad in ruby
class Writer
def flat_map
self.class.new do
value, log = get
new_value, new_log = yield value
[new_value, log + new_log]
end
end
def map
@zobar
zobar / .gitignore
Last active December 24, 2015 04:09
Option monad in Ruby
.rbenv-gemsets
def with_resource():
print 'SETUP RESOURCE'
yield
print 'CLEANUP RESOURCE'
a = with_resource()
a.next()
a.next()
OFFICIAL LETTER FROM FEDERAL BUREAU OF INVESTIGATION FBI EXECUTIVE DIRECTOR FBI
FEDERAL BUREAU OF INVESTIGATION FBI.WASHINGTON DC. ROBERT MUELLER III. FBI
SEEKING TO WIRETAP INTERNET
ATTENTION: BENEFICIARY
FROM: ROBERT MUELLER III EXECUTIVE DIRECTOR FBI FEDERAL BUREAU OF INVESTIGATION
WASHINGTON DC. FBI SEEKING TO WIRETAP INTERNET.
The federal bureau of investigation (FBI).Through our intelligence monitoring