Search code examples
functional-programmingpurescriptpurely-functionalpurescript-pux

Syntactical issue between order of two functions


Is there any order to be maintained while placing functions one another?

I just tried the code on the online compiler provided by purescript.org itself

"http://try.purescript.org"


module Main where

import Prelude
import Data.List
import Data.Array ((..))
import Data.Traversable (traverse)
import Control.Monad.Eff.Console(log)
import TryPureScript(render,withConsole)

main = render =<< withConsole do
  log $ "Hello world"

  traverse (\x -> log $ show $ x) (1..10)

  log $ "Hello world"

The code is compiling absolutely fine when the last log function is removed or when the traverse function is removed.But its not working while they are placed in such an order.These two(log & traverse) functions are working perfectly individually but not together.Help me to get out of this issue.


Solution

  • I think the error message already give you a hint, you can fix by

    _ <- traverse (\x -> log $ show $ x) (1..10)
    -- or
    void $ traverse (\x -> log $ show $ x) (1..10)