[Haskell-cafe] GADTs and Exponentiated Functors

amindfv at gmail.com amindfv at gmail.com
Sun Mar 6 16:38:19 UTC 2016


Interesting! What's the reason you redefine the Piano numbers and hide the import of the ones from GHC. TypeLits?

Tom


> El 6 mar 2016, a las 07:11, Daniel Filonik <d.filonik at hdr.qut.edu.au> escribió:
> 
> Hi,
> 
> 
> I have been recently playing around with GADTs, using them to keep track of how many times a functor has been applied. This provides a solution to what seems to be a long standing problem, summarized here:
> 
> 
> https://byorgey.wordpress.com/2007/08/16/mapping-over-a-nested-functor/
> 
> 
> If the nesting depth is part of the type, it is possible to apply fmap automatically as needed. This allows you to write fairly elegant expressions like:
> 
> 
> data Person = Person { name :: String, age :: Integer, gender :: String, status :: String } deriving Show 
> 
> let 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 `select` age
> -- [20,18,16]
> 
> 
> persons `groupby` gender `select` age
> 
> -- [[20],[18,16]]
> 
> 
> persons `groupby` gender `groupby` status `select` age
> 
> -- [[[20]],[[18],[16]]]
> 
> Note that "`select` age" works regardless of nesting depth. You can also append or remove nesting levels:
> 
> persons `groupby` gender `select` age `produce` (\x -> [0..x])
> 
> -- [[[0..20]],[[0..18],[0..16]]]
> 
> persons `groupby` gender `reduce` (sumof age)
> 
> -- [20, 34]
> 
> Would this kind of thing be of interest? The code is here:
> 
> 
> https://github.com/filonik/nlists
> 
> 
> Please feel free to suggest improvements.
> 
> 
> Cheers,
> 
> Daniel
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160306/0faf9910/attachment.html>


More information about the Haskell-Cafe mailing list