Why is my Haskell statement happening only in IHaskell?

If I define

import Control.Exception (assert)
import Data.Char (ord)

f :: String -> String
f s = assert (all (`elem` letters) s) $ (letters!!) <$> (ix <$> s)
    where
        ix ch = (ord ch - ord 'A')
        letters = ['A'..'Z']

then if I do

f "AB.CD"

in ihaskell i get

:10:7-12: Assertion failed

as i expected. But in all other settings, the statement seems to be ignored. For example, in GHCi (7.10.2) I get

ghci>f "AB.CD"
"AB*** Exception: Prelude.!!: negative index 

and if I put this expression in the program

main :: IO ()
main = do
    print $ f "AB.CD"

I get

prgm: Prelude.!!: negative index
"AB

Why is my statement ignored everywhere, but in IHaskell?


In GHCi :setgives:

options currently set: none.
base language is: Haskell2010
with the following modifiers:
  -XNoDatatypeContexts
  -XNondecreasingIndentation
GHCi-specific dynamic flag settings:
other dynamic, non-language, flag settings:
  -fimplicit-import-qualified
warning settings:
+4
source share

Source: https://habr.com/ru/post/1608585/


All Articles