Skip to content

Instantly share code, notes, and snippets.

View pepeiborra's full-sized avatar

Pepe Iborra pepeiborra

View GitHub Profile
@pepeiborra
pepeiborra / Example.hs
Created April 2, 2017 11:14
ApplicativeDo bug in GHC 8.0.2
{-# LANGUAGE ApplicativeDo, GeneralizedNewtypeDeriving #-}
import Data.Functor.Identity
import Data.Monoid
newtype A x = A (Identity x) deriving (Functor, Applicative)
-- ghc 8.0.2 does not accept bad :: A () (no instance for Monad A)
bad :: Identity ()
bad = do
@pepeiborra
pepeiborra / gist:323e1d7cca2d966c5eb9f1c97d1ef563
Last active February 20, 2017 00:09
Comparing monad-par and async over two use cases: already calculated futures, and blocking I/O
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeSynonymInstances #-}
import Control.Concurrent.Async
import Control.DeepSeq
@pepeiborra
pepeiborra / idiomaticjsonserialiser.fs
Last active August 8, 2016 17:00 — forked from isaacabraham/idiomaticjsonserialiser.fs
This JSON.Net converter handles F# discriminated unions with slightly more "idiomatic" JSON than what is generated by the current version of JSON .NET. Tuple-style properties are used rather than array notation.
namespace DU.Json
open Microsoft.FSharp.Reflection
open Newtonsoft.Json
open Newtonsoft.Json.Serialization
open System
module Exts =
type TokenValue =
{ typ : JsonToken
@pepeiborra
pepeiborra / gist:1356234
Created November 10, 2011 21:09
Hoodlums on enumerators with Neil M
{-# LANGUAGE TypeFamilies #-}
import Data.Enumerator
import Data.Monoid
e :: Monad m => Enumerator Int m [Int]
e = enumList 1 [1..10]
enumStream :: Monad m => Stream a -> Enumerator a m b
> {-# LANGUAGE GADTs #-}
> {-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
> module Typed where
> import Control.Applicative -- (Const(..))
> import Prelude hiding (Left, Right)
> import Data.Functor.Identity
> import qualified Data.Set as Set
> import Data.Set (Set)
@pepeiborra
pepeiborra / gist:825623
Created February 14, 2011 08:40
Thread safe observable collection
namespace org.jiborra
module ObjectModel =
open System.Collections
open System.Collections.ObjectModel
open System.Collections.Generic
open System.Collections.Specialized
open System.ComponentModel
open System.Threading
module Expressions where
import Data.Map (Map)
import Data.Maybe
import Text.Printf
import qualified Data.Map as Map
data ExprF k = Term Int | Op Operator k k
deriving (Show, Eq, Functor)
module Expressions where
import Data.Map (Map)
import Data.Maybe
import Text.Printf
import qualified Data.Map as Map
data ExprF k = Term Int | Op Operator k k
deriving (Show, Eq, Functor)
module Data.Evaluated where
import Data.Word
import GHC.Prim
import GHC.Exts
import Foreign
#include "ghcconfig.h"
-- | 'withLocTH' is a convenient TH macro which expands to 'withLoc' @\<source location\>@
-- It should only be used when the MonadLoc preprocessor is not available.
-- Usage:
--
-- > f x = $withLocTH $ do
-- > $withLocTH $ something
-- > x < -$withLocTH $ something-else
-- > ...
--