Question

Write a function in HASKELL to reverse a string (or list) without using the built-in reverse...

  1. Write a function in HASKELL to reverse a string (or list) without using the built-in reverse function.

          Example:

          Hello as olleh or [1,3,4,5] as [5,4,3,1].

0 0
Add a comment Improve this question Transcribed image text
Answer #1

reverseData :: [b] -> [b] --function declaration
--function definition

-- ++ is concatenation operator
reverseData [] = []
reverseData (a:input) = reverseData input ++ [a]

main = do
print(reverseData "hello") --calling a function
print(reverseData [1,3,4,5])

Output

"olleh"
[5,4,3,1]
Add a comment
Know the answer?
Add Answer to:
Write a function in HASKELL to reverse a string (or list) without using the built-in reverse...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT