#!/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
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
/*-*- 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 │ |
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
-- 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) |
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
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 |
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
module Main where | |
-- Challenge: rudimentary spam filter | |
-- given the sample blacklist and comments check to see if | |
-- the phrases in the blacklist are in the comment | |
import Data.List (isInfixOf) | |
type BlackList = [String] | |
type Comment = String |
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
module Main where | |
-- | emulate a tennis game ignoring some of the details | |
import Lib | |
import Network.Wreq | |
import Data.Aeson (Value) | |
import Control.Lens | |
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!
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 Miso.String | |
import qualified Data.Aeson as Aeson | |
import qualified Data.Text.Lazy.Encoding as E | |
import qualified Data.Text.Lazy as TL | |
main :: IO () |
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
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 |
Why Elm by Matthew Griffith http://www.oreilly.com/web-platform/free/files/why-elm.pdf
—
Javascript | Elm |
NewerOlder