This file contains 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
{-# LANGUAGE OverloadedStrings #-} | |
module Main where | |
import Control.Monad.Trans (lift) | |
import Control.Parallel (par, pseq) | |
import Data.Text.Lazy (pack) | |
import System.Random (StdGen, newStdGen, random) | |
import Web.Scotty (get, scotty, text) |
This file contains 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
a057531=[e | e<-[0..], (sum $ digits e) == (length $ divisors e)] | |
where divisors n=n:[i|i <- [1..n `div` 2], n `mod` i==0] | |
digits 0=[] | |
digits n=mod n 10: digits (div n 10) | |
*Exercitium> last $ takeWhile (<2015) a057531 | |
2006 | |
*Exercitium> head $ dropWhile (<=2015) a057531 | |
2101 | |
*Exercitium> length $ takeWhile (<=2015) a057531 |
This file contains 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
foreign import data Timeout :: ! | |
type Milliseconds = Number | |
type WithTimeout eff = Eff (t :: Timeout | eff) | |
type ContTimeout eff = ContT Unit (WithTimeout eff) | |
setTimeoutCont :: forall eff. Milliseconds -> ContTimeout eff Unit | |
setTimeoutCont = ContT <<< setTimeout |
This file contains 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
-- Purescript tutorial 12.4 Exercise 4 | |
module Spider where | |
import Files | |
import Data.Foreign | |
import Data.Foreign.Index | |
import Data.Either | |
import Data.Array | |
import Data.Traversable | |
import Data.Foldable | |
import Control.Monad.Eff |
This file contains 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
type WithST h r = Eff (st:: ST h | r) | |
add :: forall h r. STRef h String -> String -> WithST h r String | |
add ref str = modifySTRef ref (++ str) | |
renderST :: Element -> String | |
renderST = pureST <<< renderElemST | |
renderElemST :: forall h r. Element -> WithST h r String | |
renderElemST e = do |
This file contains 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
public final class Correct<T> implements Result<T> { | |
private static final long serialVersionUID = 1L; | |
public final T value; | |
public Correct(T value) { | |
super(); | |
this.value = value; | |
} |
This file contains 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
{-# LANGUAGE RecordWildCards #-} | |
module Bloomberg where | |
import Data.Time | |
import Text.Format | |
data Issue = Issue { | |
title :: String, | |
price :: Double, | |
pages :: Int, |
This file contains 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
var inject = function(iterable, initial, func) { | |
var cur = initial | |
for(var i = 0;i < iterable.length;i++) { | |
cur = func(cur, iterable[i]) | |
} | |
return cur | |
} | |
var map = function(arr, func) { | |
return inject(arr, [], function(memo, val) { |
This file contains 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
(defmacro extend-fn [name args & body] | |
`(let [old-fn# (var-get (var ~name)) | |
new-fn# (fn [& p#] | |
(let [~args p#] | |
(do ~@body))) | |
wrapper# (fn [& params#] | |
(if (= ~(count args) (count params#)) | |
(apply new-fn# params#) | |
(apply old-fn# params#)))] | |
(alter-var-root (var ~name) (constantly wrapper#)))) |
This file contains 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
;;from clojure.contrib.seq-utils | |
;;'flatten' written by Rich Hickey, | |
;;see http://groups.google.com/group/clojure/msg/385098fabfcaad9b | |
(defn flatten [x] | |
(filter (complement sequential?) | |
(rest (tree-seq sequential? seq x)))) | |
;aprox. translate from paul graham's on lisp to clojure | |
(defn flatten-ol [x] | |
(letfn [(rec [x acc] |
OlderNewer