Skip to content

Instantly share code, notes, and snippets.

View Int-taking-funcs.hs
Prelude/Data.List/Data.Vector/Data.Map:
(!!) :: [a] -> Int -> a
replicate :: Int -> a -> [a]
take :: Int -> [a] -> [a]
drop :: Int -> [a] -> [a]
splitAt :: Int -> [a] -> ([a], [a])
@chrisdone
chrisdone / 0README.md
Last active May 9, 2020
Various type inference designs/sketches
View 0README.md

Type Inference: Various Designs

I'm exploring the right data types for writing a type inference with higher kinds and poly types.

Putting more things in the type system can force you to think about more things, but it also can make it harder and more verbose to write and read algorithms.

View types.hs
{-# LANGUAGE TypeOperators, LambdaCase, StandaloneDeriving, GADTs #-}
data Type env t where
-- A constant type. Add kinds?
-- Maybe, (), Int, Either, (->), etc.
Constructor :: kind -> Type env kind
-- A free variable.
-- a
FreeVariable :: kind -> Type env kind
-- Type application.
@chrisdone
chrisdone / ackermann.dhall
Last active Apr 7, 2020 — forked from Gabriel439/ackermann.dhall
Ackermann function in Dhall
View ackermann.dhall
-- Credit to: https://news.ycombinator.com/item?id=15186988
let iterate
: (Natural Natural) Natural Natural
= \f n ->
fold (n + 1) f 1
let increment : Natural Natural = \n -> n + 1
let ackermann
@chrisdone
chrisdone / normalized applicative.hs
Last active Mar 20, 2020
normalized applicative.hs
View normalized applicative.hs
{-# LANGUAGE Strict #-}
{-# LANGUAGE Strict #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE RankNTypes, InstanceSigs, KindSignatures, GADTs, ConstraintKinds, ScopedTypeVariables #-}
-- http://neilsculthorpe.com/publications/constrained-monad-problem.pdf
import Data.Function
import Data.List.NonEmpty (NonEmpty(..))
@chrisdone
chrisdone / Control.Applicative.Normalized.hs
Created Mar 20, 2020
Control.Applicative.Normalized.hs
View Control.Applicative.Normalized.hs
{-# LANGUAGE RankNTypes, InstanceSigs, KindSignatures, GADTs, ConstraintKinds, ScopedTypeVariables #-}
-- http://neilsculthorpe.com/publications/constrained-monad-problem.pdf
import GHC.Exts
data NAF :: (* -> Constraint) -> (* -> *) -> * -> * where
Pure :: a -> NAF c t a
Ap :: c x => NAF c t (x -> a) -> t x -> NAF c t a
@chrisdone
chrisdone / Data.Functor.NormalizedConstrained.hs
Last active Mar 20, 2020
Data.Functor.NormalizedConstrained.hs
View Data.Functor.NormalizedConstrained.hs
{-# LANGUAGE RankNTypes, InstanceSigs, KindSignatures, GADTs, ConstraintKinds #-}
-- Paper: http://neilsculthorpe.com/publications/constrained-monad-problem.pdf
-- Talk: https://vimeo.com/69261960
import GHC.Exts
data NF :: (* -> Constraint) -> (* -> *) -> * -> * where
FMap :: c x => (x -> a) -> t x -> NF c t a
View RIO.ConcurrentLog.hs
{-# LANGUAGE OverloadedStrings #-}
-- |
module RIO.ConcurrentLog where
import qualified Data.ByteString.Builder as SB
import Data.List
import Data.Time
import RIO
View applicative-th.hs
applicative :: Q Exp -> [Q Exp] -> Q Exp
applicative cons [] = [| pure $(cons) |]
applicative cons (x:ys) = foldl (\inner y -> [| $(inner) <*> $(y) |]) [|$(cons) <$> $(x)|] ys
View Data.Conduit.Error.hs
-- | Conduit piping with error handling.
module Data.Conduit.Error where
import Data.Conduit.Internal
infixr 2 .|?
(.|?) :: Monad m => ConduitT a b m (Either e ()) -> ConduitT b c m (Either e r) -> ConduitT a c m (Either e r)
ConduitT left0 .|? ConduitT right0 =
ConduitT $ \rest ->
You can’t perform that action at this time.