packages feed

tuple-classes-1.0.0: test/DocTest01.hs

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeApplications #-}

module DocTest01 (main) where

import Data.Tuple.Classes (curryN', uncurryN')

-- Function wrapper that expects a unary function
printArgAndRun :: (Show a) => (a -> IO b) -> a -> IO b
printArgAndRun f x = do
    print x
    f x

-- But we have a ternary function
printTitleAndSum :: String -> Int -> Int -> IO ()
printTitleAndSum title i j = do
    putStrLn title
    print $ i + j

-- We can adapt them
printArgsTitleAndSum :: String -> Int -> Int -> IO ()
printArgsTitleAndSum =
    curryN' @3 $ printArgAndRun $ uncurryN' @3 printTitleAndSum

main :: IO ()
main = printArgsTitleAndSum "Important identity" 26885 15184