Skip to content

Instantly share code, notes, and snippets.

@owickstrom
Created August 4, 2019 13:33
Show Gist options
  • Save owickstrom/fc2a6e87b422f22045a15654acfe41b3 to your computer and use it in GitHub Desktop.
Save owickstrom/fc2a6e87b422f22045a15654acfe41b3 to your computer and use it in GitHub Desktop.
Bad Haskell
{-# OPTIONS_GHC -Wno-missing-methods #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module ThoughtLeaderTom where
import Control.Monad ((>=>))
import Data.Dynamic
import Data.Proxy
import Type.Reflection
type Map k v = [(k, v)]
type Crap = Map SomeTypeRep Dynamic
insert :: forall a. Typeable a => a -> Crap -> Crap
insert x = ((someTypeRep (Proxy @a), toDyn x):)
clookup :: forall a. Typeable a => Crap -> Maybe a
clookup = lookup (someTypeRep (Proxy @a)) >=> fromDynamic
------------------------------------------------
-- ($) :: (a -> b) -> a -> b
-- ($) :: (a -> b -> c) -> b -> (a -> c)
class Apply f x o | f x -> o where
($$) :: f -> x -> o
instance {-# INCOHERENT #-} p ~ o
=> Apply (x -> p) x o where
($$) = ($)
instance (z ~ (y -> o), Apply p x o)
=> Apply (y -> p) x z where
f $$ x = \y -> f y $$ x
busconf :: Int -> String -> Bool
busconf x y = show x == y
isThree :: Int -> Bool
isThree = busconf $$ "3"
------------------------------------------------
newtype Hours = Hours { getHours :: Int }
deriving (Eq, Show)
newtype Minutes = Minutes { getMinutes :: Int }
deriving (Eq, Show)
instance {-# INCOHERENT #-} a ~ b
=> Num ((Int -> a) -> b) where
fromInteger i c = c (fromIntegral i)
instance Num ((Int -> Minutes) -> Hours) where
fromInteger i c = Hours (fromIntegral i `div` 60)
instance Num ((Int -> Hours) -> Minutes) where
fromInteger i c = Minutes (fromIntegral i * 60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment