[mercury-users] read_term(T) and Mercury types

Goncalo Jorge Coelho e Silva l10454 at alunos.uevora.pt
Sat Apr 12 08:19:51 AEST 2003


I'm new to Mercury and it's been a while
I've been trying to get to read something
from the STD_IN (a word/term) and get
it printed.

I've tried a couple of approaches, none of which 

1) Using read_term(T) and write_string 

2) Using io__read_word(Char_List) and io__write_many(Char_List)
   and io__write_list(Char_List,"",InputString) 

 Help would be welcome. 
 The problem seems to be on dealing with the
output term type: 
and getting it to be 'casted' to a 'string'. Would
this be possible in Mercury? and/or wise? 
 On theory, the 'T' regarding the input of the
predicatre 'read_term' should accept a string, 

Description (1)

I'd get:
 in argument 1 of call to predicate `io:write_string/3':
 inter.m:036:   type error: variable `Result' has type
 inter.m:036:   expected type was `string'.
 Tried using a sort of 'cast' with 
 "with_type(Term, Type)" or "Term with_type Type"
but it's no good.

 Plus, I didn't get to find out which module  
pred 'with_type' is on.

:- module inter.

:- interface.

:- import_module io.

:- pred main(io__state, io__state).
:- mode main(di, uo) is det.

:- implementation.

:- import_module array.     
:- import_module string.    
:- import_module list.      
:- import_module term_io.   
%:- import_module type_desc.
%:- import_module std_util.

%:- type ResultS == string.

main -->
        %:- type ResultS == string.
        %Result with_type string.
        %with_type(Result, string)
        % io__write_list(Char_List,"",InputString).
        %{string__format("'-'", Char_List, InputString)},
        %{string__format("%s %i %c %f\n", Char_List, InputString)}.
        %{string__format("%s %i %c %f\n", Char_List, InputString)}.

 How can I get through this?

 Plus, if I had to declare ":- type ResultS == string."
where's the right place to do it? Between "implementation"
and "main" I get:
  inter.m:020: Error: variable on LHS of type definition.
 Before "implementation" and afterwards
"main" makes no sense to me. 

(still reading the documentation... :) )
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe

More information about the users mailing list