Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Incorrect result for (== 1) . length . filter (== ',') depending on -O level #197

@hvr

Description

@hvr

@raichoo reports a nasty bug related to text (it's still unclear what exactly is going on here, although I suspect text's RULE framework to be the culprit -- I hope so at least, as the alternative would mean that several GHC releases out there may generate wrong code):

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE BangPatterns #-}
module Main where

import Prelude hiding (length, filter)
import Data.Text

currencyParser :: Text -> Bool
currencyParser x = cond == 1
  where
    cond = length fltr
    fltr = filter (== ',') x

main :: IO ()
main = print (currencyParser "0,00")

when compiling this with -O0 or running in GHCi, the proper True output is generated. However, when compiling with -O1 the wrong False output is generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions