Skip to content

Instantly share code, notes, and snippets.

@Elvecent
Last active August 15, 2020 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Elvecent/581863e7f7991ab5340a84190d04104d to your computer and use it in GitHub Desktop.
Save Elvecent/581863e7f7991ab5340a84190d04104d to your computer and use it in GitHub Desktop.
Functor list product or idk
{-# 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