Search code examples
purescript

PureScript - how to import just the string join operator "<>"?


The following code works:

import Prelude
import Effect (Effect)
import Effect.Console (log)

message1 :: String
message1 = "Hello"

message2 :: String
message2 = "World!"

message3 :: String
message3 = message1 <> " " <> message2

main ∷ Effect Unit
main = do
  log (message3)

However, the following line,

import prelude

Uses the global import syntax, and all of prelude is imported. I would like to import only the operators being used (the <>) operator.

I've tried a few things such as

import Prelude (<>)
import Prelude (Join)
import Prelude (Data)

But they all just throw an error.

How do you import just <>?


Solution

  • You need to parenthesise the operator name:

    import Prelude ( (<>) )