Last active
August 15, 2020 21:34
-
-
Save Elvecent/581863e7f7991ab5340a84190d04104d to your computer and use it in GitHub Desktop.
Functor list product or idk
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
{-# LANGUAGE UndecidableInstances #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE KindSignatures #-} | |
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
{-# LANGUAGE PolyKinds #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE ConstraintKinds #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE TypeApplications #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
import Data.Kind | |
data HList (ts :: [Type]) where | |
HNil :: HList '[] | |
HCons :: t -> HList ts -> HList (t ': ts) | |
type family HProduct (l :: [Type -> Type]) (a :: Type) where | |
HProduct '[] _ = '[] | |
HProduct (f ': fs) a = f a ': (HProduct fs a) | |
data WhatTheFuckType fs a = | |
WhatTheFuckTerm { unfuck :: HList (HProduct fs a) } | |
instance Functor (WhatTheFuckType '[]) where | |
fmap _ (WhatTheFuckTerm HNil) = WhatTheFuckTerm HNil | |
instance (Functor f, Functor (WhatTheFuckType fs)) => | |
Functor (WhatTheFuckType (f ': fs)) | |
where | |
fmap f (WhatTheFuckTerm (HCons xa xas)) = WhatTheFuckTerm $ | |
HCons | |
(fmap f xa) | |
(unfuck @fs $ fmap f (WhatTheFuckTerm $ xas)) | |
type MuhFunctors a = WhatTheFuckType '[ Maybe, IO ] a | |
heck :: MuhFunctors String | |
heck = fmap show $ WhatTheFuckTerm $ | |
HCons (Just 12) $ | |
HCons (length <$> getLine) | |
HNil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment