nagibator's blog

By nagibator, 8 years ago, In English

I like Haskell and sometimes solve tasks using this language, but somehow I managed to choose tasks which do not require usage of ST monad. Today I tried to solve 686D - Kay and Snowflake and I needed an ST monad to turn list of parent nodes of the tree to adjacency list. Of course, everything worked fine on my computer, but when I tried to submit, CF said that I had CE:

Can't compile file:

program.hs:2:1:
    Control.Monad.ST: Can't be safely imported!
    The module itself isn't safe.

program.hs:3:1:
    Data.Array.ST: Can't be safely imported!
    The module itself isn't safe.

Here is the submission: 18723133
What do I have to do to fix it? How do I use ST or something similar? Why isn't ST safe?

  • Vote: I like it
  • +31
  • Vote: I do not like it

| Write comment?
»
8 years ago, # |
  Vote: I like it -13 Vote: I do not like it

This is Haskell's safety, your program can't possibly go wrong if it doesn't compile in the first place. Therefore working as intended.

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

'Safe' here refers to type safety. If you compile with flag -XSafe, certain modules that subvert type system are disallowed. But also, this flag disallows Template Haskell which provides the ability to execute arbitrary code at compile time. Maybe that's why at a certain point Mike enabled this flag.

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    By the way, apparently there is ghc option -trust that allows marking certain packages as trusted. If we add -XSafe -trust base to the compilation command, Template Haskell will be disallowed but all modules in base (like Control.Monad.ST) will be allowed.