Skip to content

Instantly share code, notes, and snippets.

@ekozhura
Created January 11, 2016 22:22
Show Gist options
  • Save ekozhura/991afda6b0fba1707ea4 to your computer and use it in GitHub Desktop.
Save ekozhura/991afda6b0fba1707ea4 to your computer and use it in GitHub Desktop.
{-# LANGUAGE ConstraintKinds, DataKinds, DeriveDataTypeable,
GADTs, TypeFamilies, TypeOperators, UndecidableInstances #-}
module Codewars.Kata.HelloWorld where
import Control.Arrow(first, second)
import Data.Char(toLower)
import Data.Typeable
import GHC.Exts(Constraint)
type family All (c :: * -> Constraint) (ts :: [*]) :: Constraint
type instance All c '[] = ()
type instance All c (t ': ts) = (c t, All c ts)
data HList (ts :: [*]) where
Nil :: HList '[]
(:>) :: t -> HList ts -> HList (t ': ts)
infixr 5 :>
data Delta = Greeting deriving Typeable
data Echo = Is deriving Typeable
data Hotel = This deriving Typeable
data Lima = A | Very deriving Typeable
data Oscar = Weird | Of | To deriving Typeable
data Romeo = Say deriving Typeable
data Whiskey = Way deriving Typeable
toTypeList :: All Typeable ts => HList ts -> [TypeRep]
toTypeList Nil = []
toTypeList (t:>ts) = typeOf t : toTypeList ts
greet :: String
greet = (++"!")
. unwords
. (\ ~(x,y) -> [x,y])
. first (map (toLower . head . show) . toTypeList)
. second (map (toLower . head . show) . toTypeList)
$ (This :> Is :> A :> Very :> Weird :> Nil,
Way :> To :> Say :> A :> Greeting :> Nil)
@ekozhura
Copy link
Author

Solution for kata "hello world!" by Aditu_V.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment