We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Loading...
  • Practice
  • Compete
  • Jobs
  • Leaderboard
  • Hiring developers?
  1. Practice
  2. Functional Programming
  3. Introduction
  4. Reverse a List
  5. Discussions

Reverse a List

  • Problem
  • Submissions
  • Leaderboard
  • Discussions

    You are viewing a single comment's thread. Return to all comments →

  • hycnara95 4 years ago+ 2 comments
    rev l = last l : (rev $ init l)
    
    5|
    Permalink
    • john5f35 3 years ago+ 1 comment

      It will cause an error when getting last [] or init [].

      -1|
      ParentPermalink
      • har33sh 2 years ago+ 1 comment
        • rev l = (last l) : (rev (init l)) *

        works !

        Easy way

        rev l = reverse l

        1|
        ParentPermalink
        • enricomaria_dea1 2 weeks ago+ 0 comments

          Fwiw, also rev = reverse works, but this is just copying.

          0|
          ParentPermalink
    • M_F_H 9 months ago+ 0 comments

      looks good to me (of course together with rev [] = []). Can anyone say something about compared efficiency with the foldl solutions?

      0|
      ParentPermalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature