Question: Haskell function that looks for an item in a list. If found it returns Just n where n is its position (starting from zero). Otherwise
Haskell function that looks for an item in a list. If found it returns Just n where n is its position (starting from zero). Otherwise it returns Nothing. Maybe type has definition: data Maybe a = Nothing | Just a
Write the function posn :: Eq a => a -> [a] -> Maybe Int. posn looks for an item in a list.
For example:
posn c "abcde" ? Just 2
posn a "abcde" ? Just 0
posn f "abcde" ? Nothing
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
