-
-
Save lenguyenthanh/f56731aa0c59b2c35d9520252e307486 to your computer and use it in GitHub Desktop.
Bad Haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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