Skip to content

💰 A Hodgepodge of functions for living in the OCaml ecosystem

Notifications You must be signed in to change notification settings

fxfactorial/podge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Podge is a centralization of helper functions and shortcuts that I have frequently found myself writing over and over again in OCaml. It doesn't depend on Jane Street's Core, Batteries or even Lwt. Rather Podge picks among various existing smaller packages that you probably already have installed and provides helper functions for common tasks related to usages of those libraries. Podge also provides some extra modules like the Math module.

Podge is well suited for hackathons, especially when you just want to do a quick HTTP get request for JSON data and subsequently play with the JSON.

See simple documentation online

Examples

You can install with

$ opam install podge

And use it in your projects with the podge opam package,

$ ocamlfind ocaml{opt,c} -package podge code.ml -o Example_program

Requests

Simple HTTP only requests will work, HTTPs will be added later but you can still try HTTPS based requests.

let () =
  match Podge.Web.get "http://hyegar.com" with
  | Ok (status_line, headers, body) ->
    Printf.printf "Status_line: %s\n" status_line;
    print_endline body
  | Error _ ->
    print_endline "Error"

Xml

Program for querying XML documents

<!-- This file is named doc.html -->
<outer> Some innards
  <article> A Long article ... </article>
</outer>

Podge Code

(* This file is named show_node.ml *)
#require "podge"

let () = 
  Podge.Xml.query_node_of_file ["outer";"Article"] Sys.argv.(1)
  |> print_endline

Result

$ utop show_node.ml doc.html
 A Long article ...

Overview of Modules

Everything is contained under one module, the Podge module. Modules that contain helpers for existing OCaml packages will have the same name as the package, for example Podge.Yojson contains functions for working with the yojson package. While Podge.Math contains various mathematical and statistical functions.

Probably the easiest way to learn what's provided by Podge is to look at it via ocp-browser, provided by the ocp-index package, have lambda-term installed before you install ocp-index so that ocp-browser is installed.

img

Hopefully the functions are named in such a way that you can infer the semantics/intended usage.

Yet another Standard Library Replacement?

No, this isn't yet another attempt at a standard library replacement. Rather this is one place for me to put all code that I've had scattered all around my hard-drive ranging from stuff that I've written, to useful StackOverflow answers, to IRC chats, general googling and Computer Science courses.

I focus on functionality, not new data structures or improvements of the StdLib provided data structures, functions.

Perhaps there will be something of use in here as well for you. I hope that some things here will help newcomers to the language as well or at least help with quick Python like prototyping.

About

💰 A Hodgepodge of functions for living in the OCaml ecosystem

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages