
Just a quick follow up to this, unless I am mistaken GHC TypeLits does not actually export constructors (Zero, Succ) for the Nat kind, does it? If it did that, of course I could just use those...
FYI, I have cleaned up the example a bit, adding some applicative magic, it now looks like:
data Person = Person { name :: String, age :: Integer, gender :: String, status :: String } deriving Show
persons = fromList' [Person {name="Alice", age=20, gender="F", status="Good"}, Person {name="Bob", age=18, gender="M", status="Good"}, Person {name="Chuck", age=16, gender="M", status="Bad"}] :: NList N1 Person
persons <$$> groupby (gender) <$$> orderby (age) <$$> select (age + 1) <$$> reduce (sum)
-- [21,36]
Or, if you are feeling more adventurous, you can do thing like:
let abg = persons <$$> groupby (gender) <$$> select (age) in ((/) <$> (abg <$$> select(realToFrac)) <***> (abg <$$> reduce(mean)))
[[1.0],[1.0588235294117647,0.9411764705882353]]
All operations select/reduce/produce/filterby/orderby/groupby work on arbitrarily nested lists, making this very composable.
Cheers,
Daniel
________________________________
From: Daniel Filonik
Sent: Monday, March 7, 2016 3:13 AM
To: amindfv@gmail.com
Cc: haskell-cafe@haskell.org
Subject: Re: [Haskell-cafe] GADTs and Exponentiated Functors
I started out using TypeLits, but I was running into problems with GHC's solver along these lines:
http://stackoverflow.com/questions/24734704/append-for-type-level-numbered-l...
However, I would not rule out the possibility that this was due to misuse my behalf. If you know a way to make it work, that would be exactly the kind of feedback I am looking for!
Also, I'd be curious if it is possible to write an instance of the general NFunctor for NList (which does not require explicit type annotations to work):
class NFunctor t (m :: Peano) (n :: Peano) where
pmap' :: (t (Succ m) a -> t m b) -> t (Succ n) a -> t n b
zmap' :: (t m a -> t m b) -> t n a -> t n b
smap' :: (t m a -> t (Succ m) b) -> t n a -> t (Succ n) b
Cheers,
Daniel
________________________________
From: amindfv@gmail.com