{-# 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)