Skip to content

Instantly share code, notes, and snippets.

Avatar

Tom Harding i-am-tom

View GitHub Profile
@i-am-tom
i-am-tom / bot.hs
Last active Jul 9, 2020 — forked from geekingfrog/bot.hs
Pour monsieur Charvet
View bot.hs
{-# OPTIONS_GHC -Wall -Wextra #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
import Data.Functor.Product (Product (..))
import Data.Barbie
@i-am-tom
i-am-tom / Main.hs
Created Jul 6, 2020
Variadic number functions
View Main.hs
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
------------------------------
-- PROBAT
main :: IO ()
@i-am-tom
i-am-tom / Cursed.hs
Created May 22, 2020
An oldie-but-goldie
View Cursed.hs
{-# OPTIONS_GHC -Wno-missing-methods #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NoStarIsType #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE PolyKinds #-}
@i-am-tom
i-am-tom / First_Main.hs
Last active Apr 25, 2020
Code from streams!
View First_Main.hs
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Main where
@i-am-tom
i-am-tom / Read.hs
Created Dec 23, 2019
Replacing function arguments with `MonadReader` calls.
View Read.hs
-----------------------------------------------------------
-- HOW TO ASK FOR HELP AND AVOID ARGUMENTS.
--
-- When we want to use an externally-provided package (such as logging,
-- database connections, etc) in our work code, it might require some initial
-- config that we traditionally store in our environment.
--
-- We might even require something like a database connection or file handler
-- /throughout/ the lifetime of the code, in order to make queries or similar.
--
@i-am-tom
i-am-tom / 01-DependentTypes.idr
Created Oct 10, 2019
HaskellX code examples!
View 01-DependentTypes.idr
module DependentTypes
TypeOf : {t : Type} -> t -> Type
TypeOf {t} _ = t
-- EXAMPLES
eg0 : TypeOf 3 = Integer
eg0 = Refl
@i-am-tom
i-am-tom / Main.hs
Last active Jun 27, 2019
Using Higgledy to create parser fallbacks.
View Main.hs
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MonoLocalBinds #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeApplications #-}
module Main where
import Control.Applicative (Alternative (..))
@i-am-tom
i-am-tom / FizzBuzz.hs
Last active Apr 5, 2020
Arguably the fastest implementation of FizzBuzz ever written.
View FizzBuzz.hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UnsaturatedTypeFamilies #-}
import GHC.TypeLits
import Prelude hiding (Functor, Semigroup)
type Main = (Fizz <> Buzz) <$> (0 `To` 100)
@i-am-tom
i-am-tom / Transformers.hs
Created Jun 1, 2019
A little talk for Friday afternoon.
View Transformers.hs
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE LambdaCase #-}
@i-am-tom
i-am-tom / Trolling.hs
Created May 11, 2019
Ramda-style composition where the first function must receive all arguments.
View Trolling.hs
{-# LAnguage FlexibleInstances #-}
{-# LANGuage FunctionalDependencies #-}
{-# LANGUAge GADTs #-}
{-# LANGUAGE UndecidableInstances #-}
module Trolling where
---------------------------------------------------------------------
-- VARIADIC COMPOSITION IN HASKELL (A LA RAMDA.JS).
--
-- In Haskell, we typeically think of the composition operator (or
You can’t perform that action at this time.