Skip to content

Instantly share code, notes, and snippets.

View Rydgel's full-sized avatar
😂
💯 🔥

Jérôme Mahuet Rydgel

😂
💯 🔥
View GitHub Profile
// http://underscore.io/blog/posts/2015/04/14/free-monads-are-simple.html
// updated version for scalaz 7.2.x where Free automatically applies the
// Coyoneda transform
import scalaz.{Free, ~>, Id}
import scalaz.std.list._
import scalaz.syntax.traverse._
type UserId = Int
type UserName = String
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
import Prelude hiding (log)
--------------------------------------------------------------------------------
-- The API for cloud files.
class Monad m => MonadCloud m where
saveFile :: Path -> Bytes -> m ()
@Rydgel
Rydgel / gist:310f7e4381892db6f958
Created October 15, 2015 14:30
Glut workaround on OS X
cabal install GLUT --ghc-options="-optl-Wl,-framework,GLUT" --reinstall --jobs=1
@danstn
danstn / free-monad-example.hs
Last active January 4, 2017 01:14
An example of using Free Monads for writing custom AST/DSL and its interpreters.
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveFunctor #-}
import Prelude
import Data.String
import Control.Monad.Free
type Program a r = Free (AST a) r
data AST a next =
@carymrobbins
carymrobbins / insertWith.scala
Created September 22, 2015 00:36
Implement Haskell's insertWith for Scala Map types.
implicit class RichMap[K, +V](private val m: Map[K, V]) extends AnyVal {
/**
* Based on Haskell's insertWith for Map types.
* If the provided key already exists in the map, the value inserted will be f(newValue, oldValue).
*/
def insertWith[V1 >: V](k: K, v: V1, f: (V1, V1) => V1): Map[K, V1] = {
m.updated(k, m.get(k).map(f(v, _)).getOrElse(v))
}
}
@berewt
berewt / TDT.hs
Last active September 3, 2015 07:00
Duck Typed morphisms statically typed
{import Control.Applicative ((<|>))
import Control.Monad
import Data.Data
import Data.Generics.Aliases
import Data.Monoid
trans :: (MonadPlus m, Typeable a, Typeable b) => (b -> r) -> a -> m r
trans = mkQ mzero . (return .)
mcast :: (Typeable b, Typeable r) => (a -> Maybe b) -> a -> Maybe r
@Earnestly
Earnestly / c99_ub_list.rst
Last active May 1, 2025 14:29
C99 List of Undefined Behavior (193 Cases)

C99 List of Undefined Behavior

From N1256: (See http://port70.net/~nsz/c/c99/n1256.html#J.2)

  • A "shall" or "shall not" requirement that appears outside of a constraint is violated (clause 4).
  • A nonempty source file does not end in a new-line character which is not immediately preceded by a backslash character or ends in a partial preprocessing token or comment (5.1.1.2).
  • Token concatenation produces a character sequence matching the syntax of a universal character name (5.1.1.2).
  • A program in a hosted environment does not define a function named main using one of the specified forms (5.1.2.2.1).
  • A character not in the basic source character set is encountered in a source file, except in an identifier, a character constant, a string literal, a header name, a comment, or a preprocessing token that is never converted to a token (5.2.1).
  • An identifier, comment, string literal, character constant, or header name contains an invalid multibyte character or does not
@ohanhi
ohanhi / frp.md
Last active May 6, 2024 05:17
Learning FP the hard way: Experiences on the Elm language

Learning FP the hard way: Experiences on the Elm language

by Ossi Hanhinen, @ohanhi

with the support of Futurice 💚.

Licensed under CC BY 4.0.

Editorial note

@divarvel
divarvel / mailjet.js
Created March 13, 2015 16:31
Mailjet API
var mailjet = require('mailjet');
var Promise = require('bluebird');
var _ = require('lodash');
var request = require('request');
var Mailjet = function(key, secret) {
return {
makeRequest: function(endPoint, args, method, creds) {
return new Promise(function(resolve, reject) {
@gelisam
gelisam / Main.hs
Last active October 5, 2017 10:09
Demonstrating how to use the Haxl library.
{-# LANGUAGE DeriveDataTypeable, GADTs, MultiParamTypeClasses, OverloadedStrings, StandaloneDeriving, TypeFamilies #-}
import Control.Applicative
import Control.Monad
import Data.Hashable
import Data.Typeable
import Haxl.Core
import Text.Printf
data E a where