Skip to content

Instantly share code, notes, and snippets.

@berdario
berdario / foo2.hs
Created July 22, 2016 14:19
Constant Applicative Form sharing/evaluation (will get different output in ghci or when compiled)
foo :: String -> IO ()
foo dummy = do
let (x, y) = (1, 1)
(x, y) <- pure $ (trace "x" (x+1), (trace "y" y*3)
print $ show (y + y) <> dummy
print $ show (x + x) <> dummy
foo2 x = foo (trace "outerfoo" "foo")
foo3 xs dummy = print $ show (map (+1) xs) <> dummy
@berdario
berdario / foo.hs
Created July 22, 2016 10:38
State monad does not force ordering
import Control.Monad.State (execState, get, modify)
import Debug.Trace (trace)
foo :: IO ()
foo = do
(x, y) <- pure $ flip execState (1,1) $ do
(x, y) <- get
modify (\(x, y) -> (trace "x1" (x+1), (trace "y1" y)))
(x, y) <- get
{
master = pkgs.python35Packages.buildPythonApplication (inputs // {
preUnpackHook = ''
PDIR = $(pwd)
echo "qui: $PDIR"
cd $(mktemp -d)
git clone $PDIR .
export sourceRoot="./checkprices"
'';
checkPhase = "env MYPYPATH=$PWD/stubs py.test";
let
pkgs = import ./channel.nix;
foo_project = import foo/default.nix;
main_service = cmd: {
wantedBy = [ "multi-user.target" ]; # Specify that the system wants this service to run.
after = [ "network.target" ]; # Start the webserver after the network has come up.
serviceConfig = {
ExecStart = cmd;
User = "nobody";
import Data.Exists
data Showable_ a = Showable_ a
data Showable = Showable (Exists Showable_)
instance showable_ :: (Show a) => Show (Showable_ a) where
show (Showable_ x) = show x
instance showable :: (Show (Showable_ a)) => Show Showable where
show (Showable v) = runExists show' v
groovy:000> trait A{ String duh() {"a"}}
===> true
groovy:000> trait B{ String duh() {"b"}}
===> true
groovy:000> class C implements A,B {}
===> true
groovy:000> c = new C()
===> C@797cf65c
groovy:000> def blez(A a){a.duh()+"!"}
===> true
dario@feynman /tmp> diffoscope v3.3.5-slp.tar.bz2 stackless-335-export.tar.bz2
--- v3.3.5-slp.tar.bz2
+++ stackless-335-export.tar.bz2
│ --- v3.3.5-slp.tar
├── +++ stackless-335-export.tar
│ ├── metadata
│ │ @@ -1,3977 +1,4244 @@
│ │ --rw-r--r-- 0/0 126 2014-07-28 10:49:51 stackless-dev-stackless-c856cc204b1c/.hg_archival.txt
│ │ --rw-r--r-- 0/0 584 2014-07-28 10:49:51 stackless-dev-stackless-c856cc204b1c/.bzrignore
│ │ --rw-r--r-- 0/0 891 2014-07-28 10:49:51 stackless-dev-stackless-c856cc204b1c/.gitignore
[dario@archvm ~]$ python
Python 3.5.1 (default, Dec 7 2015, 12:58:09)
[GCC 5.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 2+2
4
>>>
[dario@archvm ~]$ env PYTHONSTARTUP=a.py python
Python 3.5.1 (default, Dec 7 2015, 12:58:09)
[GCC 5.2.0] on linux
@berdario
berdario / gcd.factor
Created December 16, 2013 17:58
Both snippets are mostly the same: the factor solution is a recursive word, while the python one has an imperative iteration. The complexity of the function (in number of steps) is linear with the size of the smaller input
: gcd ( a b -- c ) over zero? [ nip ] [ over mod swap gcd ] if ;
(XEN) Xen version 4.5.1 (Ubuntu 4.5.1-0ubuntu1.1) (stefan.bader@canonical.com) (gcc (Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010) debug=n Fri Nov 6 22:29:21 UTC 2015
(XEN) Bootloader: GRUB 2.02~beta2-29
(XEN) Command line: placeholder no-real-mode edd=off pci=biosirq
(XEN) Video information:
(XEN) VGA is text mode 80x25, font 8x16
(XEN) Disc information:
(XEN) Found 0 MBR signatures
(XEN) Found 0 EDD information structures
(XEN) Multiboot-e820 RAM map:
(XEN) 0000000000000000 - 0000000000058000 (usable)