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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!