Comments (6)
FWIW - It may be worth checking out https://github.com/whitequark/ppx_deriving to avoid the camlp4 requirement for newer code.
from deriving.
You can de-sugar the syntax extension via the -dsource
argument (or even by invoking camlp4
directly). The command
ocamlfind ocamlc -dsource -linkall -syntax camlp4o -package deriving -o test test.ml
produces
type t =
| Left of int
| Right
module Show_t =
(Deriving_Show.Defaults(struct
type a = t
let format =
function
| formatter ->
((function
| Left v0 ->
(Format.pp_open_hovbox formatter 0;
(Format.pp_print_string formatter
"Left";
Format.pp_print_break formatter 1 2;
Deriving_Show.Show_int.format
formatter v0);
Format.pp_close_box formatter ())
| Right ->
Format.pp_print_string formatter
"Right") : a -> unit)
end) : (Deriving_Show.Show with type a = t))
let () =
print_endline
((let module Show =
struct
type inline = t
module Show_inline =
(Show_t : (Deriving_Show.Show with type a = inline))
include Show_inline
end in Show.show) (Left 5))
But there is still a runtime dependency (Deriving_Show
in the example).
Of course, I second the ppx_deriving
suggestion :).
from deriving.
@vasilisp thank you for your prompt response! Why is there a runtime dependency? What is it used for?
from deriving.
The library provides derivers for integers, lists, arrays, etc., e.g., your example leads to a Deriving_Show.Show_int.format
call for the integer in Left
. Without a library, the corresponding code would have to be duplicated.
Additionally, the derived code follows a functorial style; to support such a style the library needs to contain various signatures and functors (like Deriving_Show.Show
, Deriving_Show.Defaults
in your example).
from deriving.
If the library component causes a problem, look at ppx_deriving
; its plugins generally produce more self-contained code.
from deriving.
@vasilisp I'm adding to a codegen tool, so pulling in third-party libraries or even other files at all is undesirable.
from deriving.
Related Issues (16)
- missing dep in the Makefile HOT 1
- missing file or META error HOT 1
- Considering moving to OASIS HOT 1
- Fatal error: exception rule "\"type\"; type_declaration" cannot be found in entry HOT 2
- Really use OASIS HOT 7
- Jenkins configuration HOT 1
- typo the META file HOT 1
- broken syntax : module.(expression) HOT 1
- Issue a release HOT 5
- hangs in toplevel
- minor release needed
- clarify what deriving packages there are
- Migrate off camlp4 HOT 1
- does not compile with ocaml.4.08.0 HOT 1
- 'deriving' instead of 'deriving-ocsigen' HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deriving.