How to use the data type contains a function

I have the following data type definition:

newtype Combine a b = 
  Combine { unCombine :: a -> b }

      

and then I can define the following:

Prelude> let f = Combine $ \n -> Sum (n + 1)

      

My question is how to use f

?

+3


source to share


1 answer


Prelude Data.Monoid> unCombine f 1
Sum {getSum = 2}
Prelude Data.Monoid> unCombine f 42
Sum {getSum = 43}

      



+7


source







All Articles