ocamloasis

ocaml + oasis + custom module, how to compile


So i have the following files:

_oasis:

OASISFormat: 0.4
Name:        PongBattleServer
Version:     0.1.0
Synopsis:    Server for handling multi-player pong games
Authors:     Jason Miesionczek
License:     MIT
Plugins:     META (0.4), DevFiles (0.4)
Executable pongserver
  Path:       src
  BuildTools: ocamlbuild
  MainIs:     main.ml

main.ml:

open Players;;

let () =
    let mgr = new player_manager

players.ml:

type player =
    {
        name: string;
        score: int;
    }

class player_manager =
    object (self)
        val mutable player_list = ( [] : player list)
        method add p =
            player_list <- p :: player_list
    end;;

when i run make i get this error:

ocaml setup.ml -build 
/home/araxia/.opam/system/bin/ocamlfind ocamldep -modules src/main.ml > src/main.ml.depends
+ /home/araxia/.opam/system/bin/ocamlfind ocamldep -modules src/main.ml > src/main.ml.depends
File "src/main.ml", line 4, characters 32-32:
Error: Syntax error
Command exited with code 2.
E: Failure("Command ''/usr/bin/ocamlbuild' src/main.byte -tag debug' terminated with error code 10")
make: *** [build] Error 1
Makefile:7: recipe for target 'build' failed

i am new to ocaml and oasis, etc. what am i doing wrong?


Solution

  • This has nothing to do with Oasis or whatsoever, it's just when you write

    let () =
      let mgr = new player_manager
    

    OCaml expects an in keyword because either let introduces a global variable either it introduces a local variable and then you'll need a let var = expr in expr, nothing else.

    So, replace it by

    let () =
      let mgr = new player_manager in ()
    

    for now because you aren't doing anything with mgr.