Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

162
Vistas
PureScript - Pass arguments to main using the command line

PureScript programs export a main function which is invoked when you run the program. But it's unclear how to pass arguments to it, or if that is possible.

Consider the following simple program, which capitalizes a string.

module Main where

import Effect (Effect)
import Effect.Console (log)
import Prelude (Unit, discard)

import Data.String (toUpper)

message :: String 
message = "Satisfaction Rating: 8.23"

main ∷ Effect Unit
main = do
  log ( toUpper ( message ) )

Which outputs

SATISFACTION RATING: 8.23

This program is executed when spago run is invoked.

My question is as follows: How can the argument message in the code example, be passed in via the command line, creating a custom message capitalizer?

The updated run command would look something like:

spago run --message="new_message"

And the updated output would look like

NEW_MESSAGE

In short, how do you pass values to a PureScript program from outside?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

When you execute a PureScript program with spago run, it runs under Node. Therefore, to get command-line arguments, you need to as Node.

And look: there is a PureScript binding for the relevant Node facilities - the argv function from purescript-node-process. It's an effect that returns an array of arguments:

import Node.Process (argv)

main = do
  args <- argv
  log $ show args

A quick examination of spago run --help reveals that arguments can be passed to the program via the -b parameter:

spago run -b somearg

For multiple arguments, quote them:

spago run -b "somearg anotherarg"

Note that this works on Linux (and presumably macOS), but fails on Windows, where Spago for some reason ignores the quotes and tries to interpret anotherarg as its own argument. This is clearly a bug. This issue seems relevant.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda