List Info

Thread: "ocaml_beginners"::[] how to change type unit to string




"ocaml_beginners"::[] how to change type unit to string
country flaguser name
United States
2007-05-13 02:41:55

thanks!
$ ocamlc -c livenessanalysis.ml
File "livenessanalysis.ml", line 26, characters 32-46:
This expression has type unit but is here used with type string

Here is livenessanalysis code:

let g = mkGraph ()
let n1 = mkNode g
let n2 = mkNode g

let pf = Printf.printf
let spf = Printf.sprintf

let join_map f l = String.concat "," (List.map f l)
let pr_import x = pf "import b
let output_file_header imports =
let pr_import x = pf "import bits32 "tig_%s" as %s;n" x x in
List.iter pr_import imports

let emit exl =
let rec stm = function
T.LABEL l -> spf "%s:" (S.name l)
| T.CONT(l,ls) e -> spf "continuation %s(%s):"
r) (S.name l) (join_map S.name ls)
| T.JUMP e -> spf "jmp %s;" (valexp e)
| T.CJUMP(ex, l1, l2) -> spf "if(%s) {jmp %s;} else {jmp %s;}"
(boolexp ex) (S.name l1) (S.name l2)
| T.MOVE(e1, e2) -> mkEdge g n1 n2

Graphs code:

type node = string

type graph = { nodes : (node, bool) Hashtbl.t;
edges : (node, node) Hashtbl.t }

let mkGraph () =
{ nodes = Hashtbl.create 109;
edges = Hashtbl.create 109 }

let mkNode =
let ct = ref 0 in
fun g -> ct := !ct + 1;
let node = ("n" ^ (string_of_int !ct)) in
Hashtbl.add g.nodes node true; node

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] how to change type unit to string
country flaguser name
Belgium
2007-05-13 04:40:18

On Sun, 13 May 2007, LianYang < yanglian%40gmail.com">yangliangmail.com> wrote:
&gt;
> thanks!
> $ ocamlc -c livenessanalysis.ml
> File "livenessanalysis.ml", line 26, characters 32-46:
&gt; This expression has type unit but is here used with type string

Next time, show up the work you did to understand the problem! Also,
_attach_ the files, your livenessanalysis.ml below does not have 26
lines!

> let pf = Printf.printf
> let spf = Printf.sprintf

I do not recommend this. Open the Printf module and use printf and
sprintf instead.

> let join_map f l = String.concat ",&quot; (List.map f l)
> let pr_import x = pf "import b
^
You need to close the string.
Emacs with the tuareg mode will
avoid you making such silly mistakes.

> let emit exl =
> let rec stm = function
> T.LABEL l -> spf "%s:&quot; (S.name l)

Where is the definition of the variant ?

>; | T.CONT(l,ls) e -> spf "continuation %s(%s):&quot;
> r) (S.name l) (join_map S.name ls)
^
Some function is missing here.

> | T.JUMP e -> spf "jmp %s;" (valexp e)
> | T.CJUMP(ex, l1, l2) -> spf "if(%s) {jmp %s;} else {jmp %s;}"
> (boolexp ex) (S.name l1) (S.name l2)
> | T.MOVE(e1, e2) -> mkEdge g n1 n2

About your subject "how to change type unit to string&quot;

You CAN'T. This indicates an error of yours. The error means that
the compiler expects a string (because, say, other cases return a
string) but you gave an expression evaluating to () of type unit.

Cheers,
ChriS

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )