#!/usr/bin/env nix-shell
#nix-shell -p "haskellPackages.ghcWithPackages (pkgs: with pkgs; [ mwc-random ])" -i runghc
{-# LANGUAGE ScopedTypeVariables #-}
import System.Random.MWC
import Data.Vector.Unboxed
import Control.Monad.ST
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ | |
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ | |
╞══════════════════════════════════════════════════════════════════════════════╡ | |
│ Copyright 2022 Justine Alexandra Roberts Tunney │ | |
│ │ | |
│ Permission to use, copy, modify, and/or distribute this software for │ | |
│ any purpose with or without fee is hereby granted, provided that the │ | |
│ above copyright notice and this permission notice appear in all copies. │ | |
│ │ | |
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ |
-- in response to https://www.reddit.com/r/haskell/comments/duopq8/create_tests_for_other_languages_using_haskell/ | |
-- TLDR: yes, you can test C functions from Haskell; it's a bit painful to | |
-- call C from Haskell, but once you do, testing is the easy part! | |
{-# LANGUAGE QuasiQuotes, ScopedTypeVariables, TemplateHaskell #-} | |
module Main where | |
import Data.Foldable (for_) | |
import Data.Traversable (for) | |
import Foreign.C.Types (CInt, CSize) |
module Main where | |
-- | JSON is an incredibly simple format. Even its lists are untyped. | |
-- | As with all languages, functional programming encourages us to | |
-- | make a domain-specific language (or DSL) to capture the "ideas" | |
-- | of the language, which we can then use to talk about its content. | |
-- | In this little snippet, we'll build a JSON DSL, transform it into | |
-- | a recursive structure, and then use that result to generate some |
The following are appendices from Optics By Example, a comprehensive guide to optics from beginner to advanced! If you like the content below, there's plenty more where that came from; pick up the book!
fmap :: ... => (a -> b) -> (f a -> f b) | |
(.) :: (y -> z) -> (x -> y) -> (x -> z) | |
fmap :: (f2 a -> f2 b) -> (f1 (f2 a) -> f1 (f2 b)) | |
fmap :: (a -> b) -> (f2 a -> f2 b) | |
(.) :: (y -> z ) -> (x -> y ) -> (x -> z ) | |
(.) :: ((f2 a -> f2 b) -> (f1 (f2 a) -> f1 (f2 b))) -> ((a -> b) -> (f2 a -> f2 b)) -> ((a -> b) -> (f1 (f2 a) -> f1 (f2 a))) | |
(.) fmap fmap :: (a -> b) -> (f1 (f2 a) -> f1 (f2 b)) | |
^--- (.) fmap fmap = fmap . fmap |
This is a little style and expressiveness test for various stream libraries. It is certainly not a proof of anything, so much as an ability to showcase how some basic features of streams fit together with different libraries.
Problem statement: given a library of streams, implement an API analogous to fgrep
, i.e., a literal string grepper.
Specifically, implement a function fgrep(test, filenames[, limit=10])
, which takes a source string, a list of filenames, and an optional concurrency limit, and produces a stream of Match
records { filename: string, lineNumber: number, line: string }
, representing all lines of all files that contain the string test
. For each matching record, filename
is the name of the file where the match was found, lineNumber
is the one-indexed line number where the match was found, and line
is the contents of the line where the match was found.
The limit
argument indicates the maximum number of concurrent filehandles that should b
// Here is an example of a plain old function that returns a promise. | |
// Nothing magic about that. | |
function sleep(sec) { | |
return new Promise(function (resolve, reject) { | |
setTimeout(function () { | |
resolve(undefined); | |
}, sec * 1000); | |
}); | |
} |
angular.module('catalog-diff') | |
.directive 'scheduleHeatmap', -> | |
margin = | |
top: 30 | |
right: 0 | |
bottom: 30 | |
left: 30 |
# Selenium launcher is a great npm module for booting | |
# selenium server via a Node.js process. | |
selenium = require 'selenium-launcher' | |
soda = require 'soda' | |
process.env.NODE_ENV = "cucumber" | |
# This is our app's file. | |
server = require '../../server' | |
# We add some empty variables to store the web browser |