Created
January 11, 2016 22:22
-
-
Save ekozhura/991afda6b0fba1707ea4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Solution for kata "hello world!" by Aditu_V.