Skip to main content
Code Review

Return to Answer

Included code from Prelude; added warning against using reverse
Source Link
200_success
  • 145.5k
  • 22
  • 190
  • 478
  1. What happens when a string ends in a newline? lines "\n"[""], but lines' "\n"["", ""].

  2. ys could have a more informative name. line?

  3. When you find yourself wanting to add new items to the end of(削除) When you find yourself wanting to add new items to the end of a list, consider keeping the list in reverse order, adding items to the front and reversing it when it's done. This avoids needing to use ++. (削除ここまで) ("Done" is a list, consider keeping the list in reverse order, adding items to the front and reversing itfuzzy concept when it's done. This avoids needing to use ++working lazily with infinite lists.)

  4. ...but when reinventing the wheel, you needn't reinvent the axle and bearings as well. There is a Prelude function that will parse one line from a string: break. If you use that, you need only handle recursing on the remainder. This is how lines is really implemented how lines is really implemented.

     lines s = let (l, s') = break (== '\n') s
     in l : case s' of
     [] -> []
     (_:s'') -> lines s''
    
  1. What happens when a string ends in a newline? lines "\n"[""], but lines' "\n"["", ""].

  2. ys could have a more informative name. line?

  3. When you find yourself wanting to add new items to the end of a list, consider keeping the list in reverse order, adding items to the front and reversing it when it's done. This avoids needing to use ++.

  4. ...but when reinventing the wheel, you needn't reinvent the axle and bearings as well. There is a Prelude function that will parse one line from a string: break. If you use that, you need only handle recursing on the remainder. This is how lines is really implemented.

  1. What happens when a string ends in a newline? lines "\n"[""], but lines' "\n"["", ""].

  2. ys could have a more informative name. line?

  3. (削除) When you find yourself wanting to add new items to the end of a list, consider keeping the list in reverse order, adding items to the front and reversing it when it's done. This avoids needing to use ++. (削除ここまで) ("Done" is a fuzzy concept when working lazily with infinite lists.)

  4. ...but when reinventing the wheel, you needn't reinvent the axle and bearings as well. There is a Prelude function that will parse one line from a string: break. If you use that, you need only handle recursing on the remainder. This is how lines is really implemented.

     lines s = let (l, s') = break (== '\n') s
     in l : case s' of
     [] -> []
     (_:s'') -> lines s''
    
clarity
Source Link
Anonymous
  • 2.2k
  • 10
  • 14
  1. What happens when a string ends in a newline? lines "\n"[""], but lines' "\n"["", ""].

  2. ys could have a more informative name. line?

  3. When you find yourself wanting to add new items to the end of a list, consider keeping the list in reverse order, adding items to the front and reversing it when it's done. This avoids theneeding to use of ++.

  4. ...but when reinventing the wheel, you needn't reinvent the axle and bearings as well. There is a Prelude function that will parse one line from a string: break. If you use that, you need only handle recursing on the remainder. This is how lines is really implemented.

  1. What happens when a string ends in a newline? lines "\n"[""], but lines' "\n"["", ""].

  2. ys could have a more informative name. line?

  3. When you find yourself wanting to add new items to the end of a list, consider keeping the list in reverse order, adding items to the front and reversing it when it's done. This avoids the use of ++.

  4. ...but when reinventing the wheel, you needn't reinvent the axle and bearings as well. There is a Prelude function that will parse one line from a string: break. If you use that, you need only handle recursing on the remainder. This is how lines is really implemented.

  1. What happens when a string ends in a newline? lines "\n"[""], but lines' "\n"["", ""].

  2. ys could have a more informative name. line?

  3. When you find yourself wanting to add new items to the end of a list, consider keeping the list in reverse order, adding items to the front and reversing it when it's done. This avoids needing to use ++.

  4. ...but when reinventing the wheel, you needn't reinvent the axle and bearings as well. There is a Prelude function that will parse one line from a string: break. If you use that, you need only handle recursing on the remainder. This is how lines is really implemented.

Source Link
Anonymous
  • 2.2k
  • 10
  • 14
  1. What happens when a string ends in a newline? lines "\n"[""], but lines' "\n"["", ""].

  2. ys could have a more informative name. line?

  3. When you find yourself wanting to add new items to the end of a list, consider keeping the list in reverse order, adding items to the front and reversing it when it's done. This avoids the use of ++.

  4. ...but when reinventing the wheel, you needn't reinvent the axle and bearings as well. There is a Prelude function that will parse one line from a string: break. If you use that, you need only handle recursing on the remainder. This is how lines is really implemented.

lang-hs

AltStyle によって変換されたページ (->オリジナル) /