Prelude> putStr "Hello, world" Hello, world Prelude>
Prelude> "Hello" ++ ", " ++ "world" "Hello, world" Prelude>Unlike some previous versions of Hugs, there is no special treatment for values of type String; to display a string without the enclosing quotes and special escapes, you should turn it into a program using the putStr function, as shown above.
Prelude> sum [1..) ERROR: Syntax error in expression (unexpected `)') Prelude> sum 'a' ERROR: Type error in application *** expression : sum 'a' *** term : 'a' *** type : Char *** does not match : [a] Prelude> sum [1..n] ERROR: Undefined variable "n" Prelude>Another common problem occurs if there is no show function for the expression entered---that is, if its type is not an instance of the Show class. For example, suppose that a module defines a type T without a Show instance:
module Test where data T = A | BWith just these definitions, any attempt to evaluate an expression of type T will cause an error:
Test> A ERROR: Cannot find "show" function for: *** expression : A *** of type : T Test>To avoid problems like this, you will need to add an instance of the Show class to your program. One of the simplest ways to do that is to request a derived instance of Show as part of the datatype definition, as in:
module Test where data T = A | B deriving ShowOnce this has been loaded, Hugs will evaluate and display values of type T:
Test> A A Test> take 5 (cycle [A,B]) [A, B, A, B, A] Test>Values in the IO monad are only treated as programs if they return (). For example, getChar has type IO Char, so it is printed using show:
Prelude> getChar <Hugs will not execute this expression as a program because it does not specify what should be done with the character returned by getChar. If you want to run getChar as a program and, for example, discard its result, then you must do this explicitly:> Prelude>
Prelude> do getChar; return () w Prelude>
You should also note that the behaviour of the evaluator can be changed while the interpreter is running by using the :set command to modify option settings.