Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to write the identity function in haskell

Tags:

haskell

I have a function with type like this:

functionX :: [String] -> ([Integer] -> [Integer])

It is kind of like a mapping function that maps a specific String to a function with type as so. Because I need to handle the call functionX [], which I think this call should return something called identity function, or whatever, how can I write it?

like image 720
Rn2dy Avatar asked Sep 14 '26 17:09

Rn2dy


1 Answers

id is predefined as the identity function in haskell. It has type id :: a -> a.

If you wanted, you could define your own easily:

myIdentityFunction :: a -> a
myIdentityFunction a = a
like image 101
rampion Avatar answered Sep 17 '26 09:09

rampion



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!