Skip to content

Instantly share code, notes, and snippets.

@danidiaz
Last active January 19, 2019 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danidiaz/150e4e7086243b995647d52b4ba129a0 to your computer and use it in GitHub Desktop.
Save danidiaz/150e4e7086243b995647d52b4ba129a0 to your computer and use it in GitHub Desktop.
cpure_NP example
{-# 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