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
| {-# LANGUAGE OverloadedLists #-} | |
| import GHC.Exts | |
| newtype PowS' a = PowS' { fromPowS :: [a] } | |
| instance IsList (PowS' a) where | |
| type (Item (PowS' a)) = a | |
| fromList a = PowS' a | |
| toList a = fromPowS a |
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
| {-# LANGUAGE DeriveFoldable #-} | |
| import Data.List | |
| data NList a = [a] :-: (NList [a]) | |
| | Nil deriving (Show, Foldable) | |
| fixT :: NList a -> NList a | |
| fixT Nil = Nil | |
| fixT (x :-: Nil) = x :-: (subsequences x :-: Nil) |
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
| {-# LANGUAGE TypeFamilies #-} | |
| {-# LANGUAGE DataKinds #-} | |
| {-# LANGUAGE KindSignatures #-} | |
| data Nat = Z | S Nat | |
| type family Iterate (n :: Nat) f a where | |
| Iterate Z f a = a | |
| Iterate (S n) f a = f (Iterate n f a) |
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
| {-# LANGUAGE DataKinds #-} | |
| {-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
| {-# LANGUAGE OverlappingInstances #-} | |
| module Montgomery where | |
| -- type R = 2 | |
| r :: Integer | |
| r = 2 |
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
| (defn ones-in-partitions | |
| "Number of 1s in all partitions of an integer n" | |
| [n] | |
| (-> (repeat (dec n) 1) | |
| (clojure.math.combinatorics/partitions) | |
| (count))) | |
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| (defn partitions |
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
| #!/bin/bash | |
| git diff --stat 4b825dc642cb6eb9a060e54bf8d69288fbee4904 |
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
| (defn dl | |
| [& elements] | |
| (fn [x] (concat elements x))) | |
| (defn dl-un | |
| [l] | |
| (l nil)) | |
| (defn dl-concat | |
| [& lists] | |
| (fn [x] ((apply comp lists) x))) |
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
| ((lambda (x) (list x (list 'quote x))) | |
| '(lambda (x) (list x (list 'quote x)))) |
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
| (defmacro loop-while | |
| [bind condition & body] | |
| `(loop ~bind | |
| (when ~condition | |
| ~@body | |
| (recur ~@(map second (partition 2 bind)))))) |
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
| ;; Version 1: direct inline the anonymous function: | |
| (defn as-currency | |
| "Money amounts are transmitted as \"$2.44\". | |
| Parse this and return a numeric type." | |
| [currency-amount] | |
| (-> (subs currency-amount 1) | |
| ((fn [x] (println x) x)) | |
| (bigdec) | |
| ((fn [x] (println x) x)))) |