Last active
January 19, 2019 16:45
-
-
Save danidiaz/150e4e7086243b995647d52b4ba129a0 to your computer and use it in GitHub Desktop.
cpure_NP example
This file contains 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 DataKinds, TypeApplications #-} | |
-- http://hackage.haskell.org/package/sop-core | |
module Main where | |
import Data.SOP | |
import Data.SOP.NP (cpure_NP,cliftA_NP,collapse_NP) | |
import Data.Default | |
import Data.Proxy | |
-- NP is an n-ary product indexed by a type-level list. Each value is wrapped in an identity functor I. | |
defaults :: NP I '[Int, Float] | |
defaults = cpure_NP (Proxy @Default) (I def) | |
-- cliftA_NP lets us use Show for transforming the components of the product. | |
-- mapIK is an auxiliary function for transforming I-wrapped values to K-wrapped values. | |
-- K is a constant functor with an annotation that lets us store values (Strings here) unrelated to the field's type. | |
main :: IO () | |
main = print $ collapse_NP $ cliftA_NP (Proxy @Show) (mapIK show) defaults |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment