List mapMaybes/Catmaybes在Windows和Ubuntu中的工作方式可能不同

List mapMaybes/Catmaybes在Windows和Ubuntu中的工作方式可能不同,list,parsing,haskell,ubuntu,List,Parsing,Haskell,Ubuntu,我有一个Haskell程序,它读取输入文件的内容并对其进行解析,以排序和删除重复项。这个程序已经休眠一段时间了,我需要重新启动它。我告诉你们这些只是为了这个问题的历史背景 当我重新启用该程序时,我发现它不起作用。我的调试已将问题隔离到解析和“清理”输入文件的代码。这之后发生的事情对于这个问题来说无关紧要,因为我最终得到了输入文件中的候选记录的空列表 我在我的Windows笔记本电脑上编写并测试这个程序,然后在需要运行的Ubuntu服务器上部署并构建源代码。作为调试的一部分,我将文本解析分解为几个

我有一个Haskell程序,它读取输入文件的内容并对其进行解析,以排序和删除重复项。这个程序已经休眠一段时间了,我需要重新启动它。我告诉你们这些只是为了这个问题的历史背景

当我重新启用该程序时,我发现它不起作用。我的调试已将问题隔离到解析和“清理”输入文件的代码。这之后发生的事情对于这个问题来说无关紧要,因为我最终得到了输入文件中的候选记录的空列表

我在我的Windows笔记本电脑上编写并测试这个程序,然后在需要运行的Ubuntu服务器上部署并构建源代码。作为调试的一部分,我将文本解析分解为几个descreet步骤,最后一个步骤的输出上运行的部分是我得到空列表的地方,但只有在Ubuntu服务器上运行它时

以下主要是说明问题的来源:

    main = do
        [ inFileName ] <- getArgs
        sFile <- readFile inFileName
        let lrec = lines sFile
        putStrLn $ "Number of lines read from the file: " ++ show (length lrec)
        let prec = map processLine lrec
        putStrLn $ "Number of processed lines is " ++ show (length prec)
        -- let persons = mapMaybe processLine lrec
        let persons = catMaybes prec
        putStrLn $ "Number of filtered person records: " ++ show (length persons)
        let records = sortBy (compare `on` personEmployeeID) persons
        putStrLn $ "Number of records read and sorted is " ++ show (length records)

        {-
            Compare and warn about employees with duplicate records.
        -}
        let srec = groupBy ((==) `on` personEmployeeID) records
        putStrLn $ "Number of unique record groups is " ++ show (length srec)
        let dups = map (personEmployeeID . head) $ filter ((> 1) . length) srec
        putStrLn $ "Number of dups: " ++ show (length dups)
        unless (null dups) $ putStrLn $ "WARNING: Duplicate employees: " ++ show dups

        -- Remove the duplicates
        let cleanedRecords = map head srec
        putStrLn $ "Number of records in cleanedRecords is " ++ show (length cleanedRecords)
当我在windows笔记本电脑上运行此代码时,它会产生以下输出:

    Number of lines read from the file: 47793
    Number of processed lines is 47793
    Number of filtered person records: 32993
    Number of records read and sorted is 32993
    Number of unique record groups is 32949
    Number of dups: 44
    WARNING: Duplicate employees: [ {List removed for privacy } ]
    Number of records in cleanedRecords is 32949
    C:>cabal --version
    cabal-install version 1.22.4.0
    using version 1.22.3.0 of the Cabal library
    C:>ghc --version
    The Glorious Glasgow Haskell Compilation System, version 7.8.3
    Number of lines read from the file: 47793
    Number of processed lines is 47793
    Number of filtered person records: 0
    Number of records read and sorted is 0
    Number of unique record groups is 0
    Number of dups: 0
    Number of records in cleanedRecords is 0
    xx:~/$ cabal --version
    cabal-install version 0.14.0
    using version 1.14.0 of the Cabal library
    xx:~/$ ghc --version
    The Glorious Glasgow Haskell Compilation System, version 7.4.1
当我在两台不同的Ubuntu服务器(每台服务器都有不同版本的Ubuntu和Haskell)上对相同的输入文件运行相同的代码时,我得到以下输出:

    Number of lines read from the file: 47793
    Number of processed lines is 47793
    Number of filtered person records: 32993
    Number of records read and sorted is 32993
    Number of unique record groups is 32949
    Number of dups: 44
    WARNING: Duplicate employees: [ {List removed for privacy } ]
    Number of records in cleanedRecords is 32949
    C:>cabal --version
    cabal-install version 1.22.4.0
    using version 1.22.3.0 of the Cabal library
    C:>ghc --version
    The Glorious Glasgow Haskell Compilation System, version 7.8.3
    Number of lines read from the file: 47793
    Number of processed lines is 47793
    Number of filtered person records: 0
    Number of records read and sorted is 0
    Number of unique record groups is 0
    Number of dups: 0
    Number of records in cleanedRecords is 0
    xx:~/$ cabal --version
    cabal-install version 0.14.0
    using version 1.14.0 of the Cabal library
    xx:~/$ ghc --version
    The Glorious Glasgow Haskell Compilation System, version 7.4.1
…并从另一个Ubuntu服务器:

    Number of lines read from the file: 47793
    Number of processed lines is 47793
    Number of filtered person records: 0
    Number of records read and sorted is 0
    Number of unique record groups is 0
    Number of dups: 0
    Number of records in cleanedRecords is 0
    yy:~/$ cabal --version
    cabal-install version 0.10.2
    using version 1.10.2.0 of the Cabal library
    yy:~/$ ghc --version
    The Glorious Glasgow Haskell Compilation System, version 7.6.1
像往常一样,我感到困惑。我愿意尝试任何东西

有什么想法吗

戴夫,答案是

Windows与Unix行结尾

我添加了用于打印前几行输入的代码,并在每行的末尾看到了\r。我通过dos2unix运行了该文件。现在我在Ubuntu系统上得到了同样的结果

感谢您将输入文件作为问题的根源告诉我。

答案是

Windows与Unix行结尾

我添加了用于打印前几行输入的代码,并在每行的末尾看到了\r。我通过dos2unix运行了该文件。现在我在Ubuntu系统上得到了同样的结果


感谢您指出输入文件是问题的根源。

看起来差异在到达
mappaye
/
catMaybes
之前就开始了。从文件中读取的行数不同。我已经在我的Ubuntu机器上尝试了你的代码。对于文本文件中的采样行,过滤器工作正常。你确定ubuntu机器上的文件格式相同吗?例如,他们有一个非空的笔记字段吗?是的,现在我真的觉得自己很愚蠢。在我匆忙写这篇文章的过程中,我确实在我的Windows机器上使用了错误的输入文件。我已经纠正了这个错误,并编辑了OP以反映纠正后的结果。有人告诉我,我所报道的是不可能的,我同意。有人告诉我,输入文件中一定有一些差异,可以解释输出的差异。在上一个例子中,我将代码和输入文件从我的Windows笔记本电脑复制到Ubuntu服务器;因此,我相信他们是一样的。输入文件上的wc-l确认行计数。感谢您的评论。看起来差异在到达
mamamaybes
/
catMaybes
之前就开始了。从文件中读取的行数不同。我已经在我的Ubuntu机器上尝试了你的代码。对于文本文件中的采样行,过滤器工作正常。你确定ubuntu机器上的文件格式相同吗?例如,他们有一个非空的笔记字段吗?是的,现在我真的觉得自己很愚蠢。在我匆忙写这篇文章的过程中,我确实在我的Windows机器上使用了错误的输入文件。我已经纠正了这个错误,并编辑了OP以反映纠正后的结果。有人告诉我,我所报道的是不可能的,我同意。有人告诉我,输入文件中一定有一些差异,可以解释输出的差异。在上一个例子中,我将代码和输入文件从我的Windows笔记本电脑复制到Ubuntu服务器;因此,我相信他们是一样的。输入文件上的wc-l确认行计数。谢谢你的评论。