Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purescript Tutorial: unknown value logShow

Tags:

purescript

I am about an hour into learning PureScript and I've hit a snag going through the PureScript by Example Tutorial which PureScript recommended on their site. (Specifically I'm in section 2.10). I have managed to get everything installed and I am attempting to use the logShow method they describe in the tutorial. I am getting an Unknown value logShow error when I run this code:

module Main where

import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
import Math (sqrt)

main :: forall e. Eff (console :: CONSOLE | e) Unit
main = logShow (diagonal 3.0 4.0)

diagonal w h = sqrt(w * w + h * h)

I assume that logShow is a method intended to log an integer since the actual log method only takes strings. Where is this method defined? Am I failing to import something? Is my installation incorrect? Or is the tutorial skipping something?

Thanks in advance!

like image 840
warder57 Avatar asked Dec 22 '25 01:12

warder57


1 Answers

You're almost there.

Notice this line:

import Control.Monad.Eff.Console (CONSOLE, log)

Control.Monad.Eff.Console offers both log and logShow. To solve your particular problem, you just need to replace log between those parens with logShow (the first name after the (, CONSOLE, is the name of Effect).

Just in case -- The difference between the two can be seen by the types:

log     :: forall eff.        String -> Eff (console :: CONSOLE | eff) Unit
logShow :: forall a eff. Show a => a -> Eff (console :: CONSOLE | eff) Unit

Ignoring the effects for a moment...

log ::                    String -> Unit
logShow :: forall a. Show a => a -> Unit

log only prints strings, while logShow prints anything that has a Show instance.

Realistically, yes; it means logShow is simply (log <<< show). And if we go look at the source... We can find it's indeed the case.

like image 108
Ven Avatar answered Dec 24 '25 11:12

Ven