Skip to main content

Get the Reddit app

Scan this QR code to download the app now
Or check it out in the app stores

r/purescript

members
online


Purescript for full stack application? Purescript for full stack application?

I know nothing about Purescript, just read in Will Kurt's Haskell book that it's similar to Haskell syntax and usage. I just finished that book so consider myself intermediate in Haskell (novice/low-intermediate).

I'm just looking for alternatives as I'm burned out on imperative programming (after Georgia Tech OMSCS).

Web still seems to be where the jobs are so I want to do everything in pure functional programming languages (Elixir seems popular but watching a video looked a bit too magical). I've also tried Elm which I like but it's frontend only so was thinking Elm frontend and Haskell backend but if I can stick to one language for the full stack I'd rather do that.


How to write data into the console without newline? How to write data into the console without newline?

In JavaScript there are console.log() for printing with newline and process.stdout.write() for printing without. PureScript has log for the former, but I can't find any function for the latter. Is there something like process.stdout.write() in PureScript or any technique to achieve the same result?

EDIT: for those who are still looking for the answer, I do it basically like this:

Import from the packages like this:

import Node.Encoding (Encoding(..))
import Node.Process (stdout)
import Node.Stream (writeString)

Then use the functions and constructor above this way:

    _ <- writeString stdout UTF8 yourStringHere

Here are some examples with a program of mine (it's a bit more complicated though):

module PurescriptBasics.ForOutputs where
import Prelude
import Data.List as R
import Data.List.Types (List)
import Data.Maybe (Maybe(..))
import Data.String as T
import Effect (Effect)
import Effect.Console (log)
import Node.Encoding (Encoding(..))
import Node.Process (stdout)
import Node.Stream (writeString)
main :: Effect Unit
main = do
    let qaBoo = true {-·································-} :: Boolean
    let qaC16 = '\x2705' {-·····························-} :: Char
    let qaInt = -2147483648 {-··························-} :: Int
    let qaF64 = -1.7976931348623157e308 {-··············-} :: Number
    let qaStr = "string" {-·····························-} :: String
    let qaOpt = Nothing {-······························-} :: Maybe String
    let qaVec = ["v", "e", "c", "t", "o", "r"] {-·······-} :: Array String
    let qaLis = R.fromFoldable ["l", "i", "s", "t"] {-··-} :: List String
    let qr = log

    qr "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DATA"
    _ <- writeString stdout UTF8 $ show qaBoo <> "\n"
    log $ show qaBoo
    _ <- writeString stdout UTF8 $ show qaC16 <> "\n"
    log $ T.singleton $ T.codePointFromChar qaC16
    _ <- writeString stdout UTF8 $ show qaInt <> "\n"
    log $ show qaInt
    _ <- writeString stdout UTF8 $ show qaF64 <> "\n"
    log $ show qaF64
    _ <- writeString stdout UTF8 $ qaStr <> "\n"
    log qaStr
    _ <- writeString stdout UTF8 $ show qaOpt <> "\n"
    log $ show qaOpt
    _ <- writeString stdout UTF8 $ show qaVec <> "\n"
    log $ show qaVec
    _ <- writeString stdout UTF8 $ show qaLis <> "\n"
    log $ show qaLis