2

Suppose I have some interface file mylib.mli like

var foo      : 'a list -> int
val bar      : f:('a -> 'b) -> 'a list -> 'b list
val baz      : f:('a -> bool) -> 'a list -> 'a list
val frobnitz : init:'acc -> f:('acc -> 'a -> 'acc) -> 'a list -> 'acc
val frobozz  : 'a list -> 'a list -> 'a list
val quux     : 'a list list -> 'a list

Is there an automated way to generate the corresponding mylib.ml as a collection of stubs? (By "stub" I mean a "minimal, interface-implementing function".)

kjo
  • 33,683
  • 52
  • 148
  • 265

2 Answers2

4

AFAIK, there is no such tool currently written. Maybe, because it is not a big work to do it manually. The easiest way to write a stub is:

let foo = failwith "not implemented"

or you can just make it in a following way

let stub _ = failwith "unimplemented"

let foo = stub
let bar = stub
...
ivg
  • 34,431
  • 2
  • 35
  • 63
1

For what it's worth, the -i flag of the compilers translates in the other direction.

$ cat stubs.ml
let foo (x: 'a list) = 3
let bar ~f: f l = List.map f l
let baz ~f: p l = List.filter p l
$ ocamlc -i stubs.ml
val foo : 'a list -> int
val bar : f:('a -> 'b) -> 'a list -> 'b list
val baz : f:('a -> bool) -> 'a list -> 'a list

Update

Here's some interesting discussion in the context of Haskell:

Given a Haskell type signature, is it possible to generate the code automatically?

Community
  • 1
  • 1
Jeffrey Scofield
  • 65,646
  • 2
  • 72
  • 108
  • yep, but good practice is to start from `*.mli`. And a better suggestion would be to use `corebuild stubs.inferred.mli`, imho. – ivg Nov 08 '14 at 19:49