Coder Social home page Coder Social logo

core-hello-world's Introduction

Core and Async Hello World

A simple hello-world project for using Core and Async. The intent is to show you how to get started building OCaml projects using opam, core, async, and jbuilder.

We assume that you can install OCaml and opam on your platform. You'll need to install async, core, and textutils:

$ opam install async core textutils

If you're using Merlin, you also might want to pin to the latest version:

$ opam pin add merlin --dev-repo

And you should consider installing the user-setup package to set up your editor configs to use Merlin properly. This will give you interactive feedback on compilation failures, type-throwback and auto-completion.

Once that's done, you can build all the pieces of this project by running:

$ ./build_all.sh

Or you can build an individual file by calling out to jbuilder directly

$  jbuilder build hello_world.exe

There are three basic examples.

Hello World

This is a very simple exercise that shows you how to make a basic command-line application using Core's Command module.

This executable is hello_world.exe (or hello_world.bc, for bytecode), and here's an example of it in action.

core-hello-world $ ./hello_world.exe
Hello World!
core-hello-world $ ./hello_world.exe -help
Hello World

  hello_world.exe

=== flags ===

  [-hello]       The 'hello' of 'hello world'
  [-world]       The 'world' of 'hello world'
  [-build-info]  print info about this build and exit
  [-version]     print the version of this build and exit
  [-help]        print this help text and exit
                 (alias: -?)

core-hello-world $ ./hello_world.exe -hello "Goodbye" -world "Yellow Brick Road"
Goodbye Yellow Brick Road!

Hello World client/server

The next example is a pair of programs: hello_server.exe and hello_client.exe. The server will accept requests via the Async.Rpc library, and the client dispatches them. The RPC is trivial: the client sends a string, and the server attaches " World!" to the end of it and sends the result back.

Message Broker

This is the most complicated example. broker_server.exe is a simple message broker that allows you to publish and subscribe to streams of data. broker_client.exe is a client that lets you do a few operations, including publishing, subscribing, getting a dump of the current state of the server, and shutting the server down.

Setting up the toplevel

You can use the built-in OCaml toplevel, ocaml, but you're probably better off using utop, which you can install via opam:

$ opam install utop

There's also a file called dot_ocamlinit, which will auto-load core and async, if you do this:

$ cp dot_ocamlinit ~/.ocamlinit

And now you can start the toplevel.

$ utop

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.