Often when writing programs and functions, one starts off with concrete types that solve the problem at hand. At some later time, due to emerging requirements or observed patterns, or just to improve code readability and reusability, we refactor to make our code more polymorphic. The importance of not breaking your API typically ranges from nice to have (e.g. minimises rework but not essential) to paramount (e.g. in a popular, foundational library).
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
module type Monad = sig | |
type 'a t | |
val return: 'a -> 'a t | |
val bind: 'a t -> ('a -> 'b t) -> 'b t | |
end |
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 GADTs #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE PolyKinds #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
{-# LANGUAGE ConstraintKinds #-} | |
import Data.Constraint | |
import Data.Function |
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
-- To run: | |
-- cabal repl -b pretty-simple | |
-- | |
-- Colorizing and pretty-printing ghci output | |
-- requires: pretty-simple | |
:set -interactive-print=Text.Pretty.Simple.pPrint | |
-- green bold lambdas and multiline mode | |
:set prompt "\ESC[1;32mλ: \ESC[m" | |
:set prompt-cont "\ESC[1;32mλ| \ESC[m" |
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
{-# OPTIONS_GHC -Wall #-} | |
{-# LANGUAGE DeriveAnyClass #-} | |
{-# LANGUAGE DeriveDataTypeable #-} | |
{-# LANGUAGE LambdaCase #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE PartialTypeSignatures #-} | |
module RegAlloc1 | |
( -- * Types | |
Var |
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
import Control.Monad.IO.Class | |
import Control.Monad.Codensity | |
import System.IO | |
managedActions :: Codensity IO () | |
managedActions = do | |
input <- Codensity $ withFile "in.txt" ReadMode | |
output <- Codensity $ withFile "out.txt" WriteMode | |
contents <- liftIO $ hGetContents input |
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
/** | |
* Making promises | |
*/ | |
let okPromise = Js.Promise.make((~resolve, ~reject as _) => [@bs] resolve("ok")); | |
/* Simpler promise creation for static values */ | |
Js.Promise.resolve("easy"); | |
Js.Promise.reject(Invalid_argument("too easy")); |
- https://github.com/arnarthor/advent-of-code-2017 (Native & BuckleScript)
- https://github.com/rrdelaney/advent-of-code-2017 (Native)
- https://github.com/fazouane-marouane/advent-of-code-2017 (BuckleScript)
- https://github.com/jaredly/advent-2017 (BuckleScript)
- https://github.com/brentbaum/advent-of-code (BuckleScript)
- https://github.com/Lokeh/advent-2017 (BuckleScript)
- https://github.com/wyze/advent-of-code-2017 (BuckleScript)
- https://github.com/brentvatne/advent-of-code-2017 (BuckleScript)
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 DeriveGeneric #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
module Main where | |
import Data.Foldable (for_) | |
import Data.Traversable (for) | |
import Control.Monad.IO.Class | |
-- build-depends: base, haskeline, optparse-applicative | |
-- -- for example parser |
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
#!/usr/bin/env stack | |
-- stack --resolver lts-10.0 script | |
{-# LANGUAGE OverloadedStrings #-} | |
import Text.XML | |
import qualified Data.Map.Strict as Map | |
main :: IO () | |
main = do | |
Document x (Element n a nodes) y <- Text.XML.readFile def "foo.html" | |
Text.XML.writeFile def "foo2.html" $ Document x (Element n a $ concatMap goN nodes) y |