softshipper
softshipper

Reputation: 34099

How to use a data type contains function

I have following data type definition:

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

and then I can defined as follow:

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

My question is, how to use f?

Upvotes: 3

Views: 68

Answers (1)

Mark Seemann
Mark Seemann

Reputation: 233377

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

Upvotes: 7

Related Questions