Skip to content

Instantly share code, notes, and snippets.

View juanbono's full-sized avatar
:shipit:

Juan Bono juanbono

:shipit:
View GitHub Profile
@juanbono
juanbono / BasicServer.re
Created January 2, 2018 07:58 — forked from jaredly/BasicServer.re
Simple Static File Server in Reason/OCaml
let recv = (client, maxlen) => {
let bytes = Bytes.create(maxlen);
let len = Unix.recv(client, bytes, 0, maxlen, []);
Bytes.sub_string(bytes, 0, len)
};
let parse_top = top => {
let parts = Str.split(Str.regexp("[ \t]+"), top);
switch (parts) {
@juanbono
juanbono / html-cleanup.hs
Created December 27, 2017 07:48 — forked from snoyberg/html-cleanup.hs
Small example of xml-conduit for cleaning up some HTML: remove unneeded <span>s and convert <br>s to \n
#!/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
@juanbono
juanbono / promises.re
Created December 15, 2017 22:15 — forked from lilactown/promises.re
Notes on using JavaScript Promises in ReasonML/BuckleScript
/**
* 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"));
{-# 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
@juanbono
juanbono / monads.ml
Created December 11, 2017 03:43 — forked from lindig/monads.ml
module type Monad = sig
type 'a t
val return: 'a -> 'a t
val bind: 'a t -> ('a -> 'b t) -> 'b t
end
@juanbono
juanbono / existential_types_haskell.md
Created November 29, 2017 18:12 — forked from CMCDragonkai/existential_types_haskell.md
Existential Types in Haskell

Existential Types in Haskell

I had always been confused by Haskell's implementation of existential types. Until now!

Existential types is the algebraic data type (ADT) equivalent to OOP's data encapsulation. It's a way of hiding a type within a type. Hiding it in such a way that any consumer of the data type won't have any knowledge on the internal property

@juanbono
juanbono / trolling_haskell
Created May 1, 2017 07:29 — forked from quchen/trolling_haskell
Trolling #haskell
13:15 <xQuasar> | HASKELL IS FOR FUCKIN FAGGOTS. YOU'RE ALL A BUNCH OF
| FUCKIN PUSSIES
13:15 <xQuasar> | JAVASCRIPT FOR LIFE FAGS
13:16 <luite> | hello
13:16 <ChongLi> | somebody has a mental illness!
13:16 <merijn> | Wow...I suddenly see the error of my ways and feel
| compelled to write Node.js!
13:16 <genisage> | hi
13:16 <luite> | you might be pleased to learn that you can compile
| haskell to javascript now

Refactoring with type classes and optics

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).