This blog post series has moved here.
You might also be interested in the 2016 version.
This blog post series has moved here.
You might also be interested in the 2016 version.
## Principal type-schemes for functional programs | |
**Luis Damas and Robin Milner, POPL '82** | |
> module W where | |
> import Data.List | |
> import Data.Maybe | |
> import Data.Function |
{-# language FlexibleContexts #-} | |
{-# language TypeOperators #-} | |
module DKT where | |
import Control.Monad (guard) | |
import Control.Monad.Error.Class (throwError) | |
import Control.Monad.Trans (lift) | |
import Control.Monad.Trans.State | |
import Control.Monad.Trans.Writer |
At DICOM Grid, we recently made the decision to use Haskell for some of our newer projects, mostly small, independent web services. This isn't the first time I've had the opportunity to use Haskell at work - I had previously used Haskell to write tools to automate some processes like generation of documentation for TypeScript code - but this is the first time we will be deploying Haskell code into production.
Over the past few months, I have been working on two Haskell services:
I will write here mostly about the first project, since it is a self-contained project which provides a good example of the power of Haskell. Moreover, the proces
"use strict"; | |
// module UnderscoreFFI | |
exports.map = function(f) { | |
return function (arr) { | |
return require('underscore').map(arr, f); | |
}; | |
}; |
{-# language TypeInType #-} | |
-- | Types which have PureScript equivalents | |
class ToPursTyCon a where | |
toPursTyCon :: Tagged a PursTypeConstructor | |
-- | The default instance uses 'G.Generic' and pattern matches on the | |
-- type's representation to create a PureScript type. | |
default toPursTyCon :: (G.Generic a, GenericToPursTyCon (G.Rep a)) => Tagged a PursTypeConstructor | |
toPursTyCon = retag $ genericToPursTyConWith @(G.Rep a) defaultPursTypeOptions |
module Main where | |
main = Debug.Trace.trace ("module Main where\n\n" ++ code ++ "\n where code = \"\"\"" ++ code ++ "\"\"\"") | |
where code = """main = Debug.Trace.trace ("module Main where\n\n" ++ code ++ "\n where code = \"\"\"" ++ code ++ "\"\"\"")""" |
While thinking about comonads as spaces and Day convolution, I realized an interesting thing. The free applicative functor generated by a comonad f
is also a comonad.
The free applicative can be defined in a few different ways, but I like to define it like this:
data FreeApplicative f a = Pure a | Free (Day f (FreeApplicative f) a)
module Main where | |
import Data.Maybe (fromMaybe) | |
import Control.Applicative | |
import Control.Arrow (first) | |
import Control.Monad (ap) | |
import Debug.Trace | |
module Control.Monad.List.Trans where | |
import Prelude | |
import Data.List | |
import Data.Either | |
import Control.Apply | |
import Control.Bind | |
import Control.Monad.Eff |