Skip to content

Instantly share code, notes, and snippets.


Tony Morris tonymorris

View GitHub Profile
View skipRight.hs
skipRight ::
(a -> [a] -> ([a] -> b) -> b)
-> b
-> [a]
-> b
skipRight _ z [] =
skipRight f z (h:t) =
f h t (skipRight f z)
View ValidationT.hs
import Control.Applicative(Alternative(..), liftA2)
newtype ValidationT f a b =
ValidationT (f (Either a b))
instance Functor f => Functor (ValidationT f a) where
fmap f (ValidationT x) =
ValidationT (fmap (fmap f) x)
instance Applicative f => Applicative (ValidationT f a) where
View c182_wb.hs
#!/usr/bin/env runhaskell
module Main where
import Text.Printf(printf)
import Data.List(intercalate)
import Data.Bool (bool)
kg2lb =
tonymorris / main.hs
Created Jul 2, 2021 — forked from gregberns/main.hs
How to make a Foldable Instance with multiple parameters
View main.hs
import Data.Monoid
-- This code doesn't work...
-- How can you make a multi-parameter data type be Foldable?
-- foldMap over `a` so it can be converted to a Monoid
data BinaryTree3 a v
= Node3 a (BinaryTree3 a v) (BinaryTree3 a v)
| Leaf3 a v
deriving (Show)
View 1-in-60-error.hs
#!/usr/bin/env runhaskell
import Text.Printf
fromRadian a = a / pi * 180
toRadian a = a / 180 * pi
showDiff :: Int -> String
showDiff x =
let x' = toRadian (fromIntegral x)
diff = fromRadian (x' - sin x')
View echo.hs
#!/usr/bin/env runhaskell
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveFoldable #-}
import Data.Foldable
import Text.Printf
data Point a =
Point {
View lsystem.hs
data LSystem a b =
(a -> [b])
type LSystem' a =
LSystem a a
instance Functor (LSystem a) where
fmap k (LSystem a f) =
View store.hs
f :: Store a b -> Store a (Store a b)
f s =
let (set, get) = runStore s
in store (store set) get
View prisms.hs
{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens
data These a b =
This a
| That b
| Both a b
deriving (Eq, Show)
View blah.hs
{-# LANGUAGE LambdaCase #-}
import Control.Lens
data Blah a =
Blah1 a
| Blah2 a
| BlahS String
deriving (Eq, Show)