当前位置: 动力学知识库 > 问答 > 编程问答 >

haskell - interact (concat . sort lines) cba

问题描述:

Why is the code below not working- it is not giving the desired output.I want it to sort a string(e.g cba -> abc ) .After I signal end of file with

^D i just get: cba .

import Data.List

import Data.Char

import System.IO (isEOF)

main =

interact (concat . sort .lines)

网友答案:

Looks like you want something more like:

import Data.List

main = interact (unlines . map sort . lines)

This sorts each line entered.

分享给朋友:
您可能感兴趣的文章:
随机阅读: