博客首页
注册
建议与交流
排行榜
加入友情链接
推荐
投诉
搜索:
帮助
好好学习
bilbo.cublog.cn
管理博客
发表文章
留言
收藏夹
· Compiler
· Unix_Linux
博客圈
音乐
相册
文章
· AutoHotKey
· C/C++
· Caml
· Perl
· Tcl & Expect
· 其他编程语言
· Visual Language
· Compiler Engineering
· Embedded System
· Formal methods
· FieldBus
· Networking
· Hardware Desing
· Safety System
· Unix_Linux
· Software Engineering
· GSM/GSM-R
· 技术幽默
· 读书时间
· Good Resource
· 关注社会
· 胡言乱语
首页
关于作者
姓名:你知道 职业:IT 年龄:每年大一岁 位置:地球 个性介绍:挺笨 Email: bilbo0214@163.com
||
<<
>>
||
我的分类
文章列表 - Caml
GUI wrapper for DLL/LIB to .a file
闲的无聊用ocaml写了一个DLL/LIB转.A文件的GUI封装。使用的是labtk,ocaml的强类型的确是比较强,害的我filepattern的值改了半天才编译过去。<br><br>手动执行转换可以参加下面的文档:<br><table style="border-collapse: collapse;" align="center" border="1" bordercolor="#dddddd" cellpadding="0" cellspacing="0" width="360"> <tbody><tr height="60"><td align="center" width="60"><img src="/fileicon/pdf.gif" alt="" border="0"></td><td> <table style="border-collapse: collapse;" border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr height="20"><td align="center" width="40">文件:</td><td>将dll或lib文件转换成a文件.pdf</td></tr> <tr height="20"><td align="center" width="40">大小:</td><td>44KB</td></tr> <tr height="20"><td align="center" width="40">下载:</td><td><a href="http://blogimg.chinaunix.net/blog/upfile2/080827174953.pdf">下载</a></td></tr> </tbody></table> </td></tr> </tbody></table><br><br>GUI版本的ocaml源代码如下:<br><div style="border: 2px solid rgb(0, 0, 221); backgroun……
查看全文
发表于:2008-08-27 ┆
阅读(129)
┆
评论(0)
(转)One-Day Compilers
<br><table style="border-collapse: collapse;" align="center" border="1" bordercolor="#dddddd" cellpadding="0" cellspacing="0" width="360"> <tbody><tr height="60"><td align="center" width="60"><img src="/fileicon/rar.gif" alt="" border="0"></td><td> <table style="border-collapse: collapse;" border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr height="20"><td align="center" width="40">文件:</td><td>One-Day Compilers.rar</td></tr> <tr height="20"><td align="center" width="40">大小:</td><td>49KB</td></tr> <tr height="20"><td align="center" width="40">下载:</td><td><a href="http://blogimg.chinaunix.net/blog/upfile2/080817220014.rar">下载</a></td></tr> </tbody></table> </td></tr> </tbody></table><br>一个介绍用ocaml工具集制作DSL(domain-specific language)编译器的讲义。<br>
查看全文
发表于:2008-08-17 ┆
阅读(129)
┆
评论(0)
(转)How to wrap C functions to OCaml
<div> This document is a small tutorial that introduces how to call C functions from OCaml. Which is usefull if you want to make a mixed C and OCaml application, if you want to call some functions you need from a C library, or to write a complete binding to a C library. </div><br><hr> <h3><span>Contents</span></h3> <ul><li><a href="http://www.linux-nantes.org/%7Efmonnier/OCaml/ocaml-wrapping-c.php#ref_quick_start"><span>Quick start</span></a></li><li><a href="http://www.linux-nantes.org/%7Efmonnier/OCaml/ocaml-wrapping-c.php#ref_compile"><span>Compiling C and OCaml together</span></a></li><li><a href="http://www.linux-nantes.org/%7Efmonnier/OCaml/ocaml-wrapping-c.php#ref_basic_types"><span>Returning Basic Types</span></a></li><li><a href="http://www.linux-nantes.org/%7Efmonnier/OCaml/ocaml-wrapping-c.php#ref_tuple_access"><span>Accessing Tuples</span></a></li><li><a href="http://www.linux-nantes.org/%7Efmonnier/OCaml/ocaml-wrapping-c.php#……
查看全文
发表于:2008-08-01 ┆
阅读(137)
┆
评论(0)
(转)Win32 DLL from OCaml lib
<div class="content"> <div> <div class="intro"> <div class="title">ODLL</div> <p> If you're having a boss asking you to write C librairies but if you prefer to write them in OCaml, this tool is for you ! ODLL is creating a Win32 DLL from an OCaml library, and automatically generating the C stubs needed to interface the OCaml code and the C code and the .H interface. Simply run ODLL with you CMA/CMXA and one or several CMI interfaces and ODLL will do the job for you.</p> </div> <h2>Installation</h2> <p> Since ODLL require one part of the OCaml sources, you'll need to get them from the INRIA CVS if you want to recompile ODLL. For convenience, a precompiled version is included in the distribution, which only require OCaml to be installed. You only need the odll.exe file to use odll. A sample is provided in the /sample directory. </p> <h2>Usage</h2> <ul><li>First, create an OCaml library (CMA or CMXA) using ocaml compilers (ocamlc or ocamlopt).</li>……
查看全文
发表于:2008-08-01 ┆
阅读(146)
┆
评论(0)
(转)OCaml数据类型和匹配
<div id="post-96" class="hentry p1 page publish author-shiningray category-diary tag-ocaml tag-%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b y2007 m12 d28 h20"> <h2 class="entry-title">数据类型和匹配</h2> <div class="entry-content"> <p>原文地址:<a href="http://www.ocaml-tutorial.org/data_types_and_matching" rel="external">http://www.ocaml-tutorial.org/data_types_and_matching</a> 翻译:<a href="http://wiki.nirvanastudio.org/wiki/ShiningRay">ShiningRay</a></p> <h2><a name="Linked_lists" id="Linked_lists">链表(Linked List)</a></h2> <p class="first_para">和Perl一样,OCaml也将对列表的支持直接内建在语言中了。OCaml中一个列表的所有元素的类型必须一致。使用以下格式来写列表:</p> <pre class="code" lang="ocaml">[1; 2; 3]<br></pre> <p class="first_para">(注意是分号,不是逗号)。</p> <p><code>[]</code> 表示空列表。</p> <p>一个列表有一个“<strong>头</strong>”(第一个元素)和一个“<strong>尾</strong>”(剩下的元素)。头是一个元素,而尾则是一个列表,所以前面的例子中,表头是整数<code>1</cod……
查看全文
发表于:2008-07-31 ┆
阅读(109)
┆
评论(0)
line counter in OCaml
<pre><code><span style="font-family: Courier New; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><span class="cpp1-symbol">(*<br> line counter in OCaml.<br> <br> Jun </span><span class="cpp1-number">17</span><span class="cpp1-symbol">, </span><span class="cpp1-number">2008<br></span><span class="cpp1-space"> <br> command to build </span><span class="cpp1-reservedword">this</span><span class="cpp1-space"> program:<br> ocamllex count.mll<br> ocamlc count.ml -o count.exe<br> <br> command to test </span><span class="cpp1-reservedword">this</span><span class="cpp1-space"> program:<br> count < count.mll<br>*)<br><br>{<br> let num_lines = ref </span><span class="cpp1-number">0<br></span><span class="cpp1-space"> let num_chars = ref </span><span class="cpp1-number">0<br></span><span class="cpp1-symbol">}<br><br>rule count = parse<br> | '\n' ……
查看全文
发表于:2008-07-17 ┆
阅读(148)
┆
评论(0)
straight-line program interpreter in OCaml
<pre><code><span style="font-family: Courier New; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"><span class="cpp1-symbol">(* straight-line program interpreter in OCaml *)<br>(* Ch</span><span class="cpp1-float">.1</span><span class="cpp1-space"> Programming excercise in Modern Compiler Implementation in ML *)<br><br>(*--------------------------------------------------------------------------*)<br>(* straight-line program abstract grammar tree definition *)<br>(*--------------------------------------------------------------------------*)<br>type id = string;;<br><br>type binop = Plus | Minus | Times | Div;;<br><br>(* Notes: OCaml support the following grammar<br> type-definition ::= type </span><span class="cpp1-reservedword">typedef</span><span class="cpp1-space"> { and </span><span class="cpp1-reservedword">typedef</span><spa……
查看全文
发表于:2008-07-08 ┆
阅读(148)
┆
评论(0)
(转)SML vs. OCaml
<h1> Standard ML and Objective Caml, Side by Side </h1> <p> This page gives a quick side by side comparison of program fragments in the two ML dialects <a href="http://mitpress.mit.edu/book-home.tcl?isbn=0262631814">Standard ML</a> ('97 revision) and <a href="http://caml.inria.fr/ocaml/htmlman/">Objective Caml</a> (version 3). It is primarily targetted at people who need to convert code between the two dialects. Where suitable we also mention common extensions to SML, or recent extensions of Ocaml. The comparison does not cover features that do not have an appropriate counter part in the sibling dialect (eg. Ocaml's object sublanguage, SML's user-defined operator fixity, or advanced library issues). </p> <p> The first section is an interaction with the respective toplevel system, in order to show the built-in types. The rest just consists of example expressions and definitions. Keywords and other reserved symbols are type-set in <font color="#0000ff">blue</font>.……
查看全文
发表于:2008-07-02 ┆
阅读(161)
┆
评论(0)
Game of Life 0.1 in Object Caml
<DIV>终于拿OCaml写了一个程序,实现一个叫Game of Life的程序。</DIV> <DIV>关于Game of Life,可以参考下面两篇文章<A href="http://pzy84.blogspot.com/2007/05/game-of-life.html">http://pzy84.blogspot.com/2007/05/game-of-life.html</A>和<A href="http://www.xinside.net/2006/09/game-of-life.html">http://www.xinside.net/2006/09/game-of-life.html</A>,写的都还不错。</DIV> <DIV> </DIV> <DIV>我这个版本就比较初级了,所以叫0.1,主要原因是算法效率很低--O(n^2),也不可以定制--只支持40x40个cell的grid,随机性也不好--随机函数看上去一点儿都不随机。不过好歹是用OCaml写的程序。</DIV> <DIV>下面两张图是运行过程中的截图,每一秒产生一代。</DIV> <DIV> </DIV> <DIV> <DIV align=center><IMG src="http://blogimg.chinaunix.net/blog/upfile2/080610121343.jpg" onload="javascript:if(this.width>500)this.width=500;" border=0></DIV></DIV> <DIV> </DIV> <DIV align=center><IMG src="http://blogimg.chinaunix.net/blog/upfile2/080610121357.jpg" onload="javascript:if(this.width>500)this.width=500;" border=0>……
查看全文
发表于:2008-06-10 ┆
阅读(212)
┆
评论(1)
(转)OCaml programming best practice
OCaml is a very big and complex language, like C++, and many parts ofit kinda stick out, are experiments that didn't go well, or exist only for backward compatibility.<br><br>If you want to code OCaml, you might find these hints useful.<br><br><ul><br><li>"Exceptions" in OCaml won't give you a backtrace. This is easily one of the top 3 worst things about OCaml. So even in situations when you'd use an exception in Ruby/Python/Java/etc., think whether you can do something else in OCaml.<br><ul><br><li>For handling "can't happen" situations use something like <span style="font-family: monospace;">failwith (sprintf "Internal error: function foo(%d, %s, %s) expects a non-empty list" a b (foo_to_string c))</span>. Because you won't get a backtrace, you should include as much information as possible.</li><br></ul><br></li><br><li>OCaml's standard library is one of its weakest parts. <b>Always</b> use <a href="http://ocaml-lib.sourceforge.net/">extensions to the std library</a>. If you ……
查看全文
发表于:2008-06-08 ┆
阅读(254)
┆
评论(0)
(转)Recursion
<h2>A (hopefully) painless introduction to recursion</h2> How recursion works, and why it's more powerful than regular looping <table style="border-spacing: 1em 0.5em; width: 50em; text-align: left;"><tbody><tr> <td colspan="2"> <a href="http://www.prairienet.org/%7Edsb/recursion.htm#tail">tail-recursive calls (tail recursion)</a> <br><a href="http://www.prairienet.org/%7Edsb/recursion.htm#why">why recursion?</a> <br><a href="http://www.prairienet.org/%7Edsb/recursion.htm#trees">recursing through tree structures</a> <br> <br> </td></tr> <tr> <th> <a name="looping"> looping with recursion </a></th> <td> Although recursion isn't technically required for simple looping, it's surprisingly versatile and ultimately more expressive. We'll discuss recursion in two phases: First a simple problem where you don't really need recursion but it's easy to understand; then a harder problem where recursion works wonders. <p> For the simple problem to get us st……
查看全文
发表于:2008-06-08 ┆
阅读(190)
┆
评论(0)
quicksort in OCaml
(* qsort *)<br><span style="color: rgb(0, 1, 255);">let rec qsort lst = match lst with</span><br style="color: rgb(0, 1, 255);"><span style="color: rgb(0, 1, 255);"> [] -> []</span><br style="color: rgb(0, 1, 255);"><span style="color: rgb(0, 1, 255);"> | x::xs -> qsort (List.filter (fun y -> y <= x) xs) @ [x] @ qsort (List.filter (fun y -> y > x) xs);; </span><br><br>open Format;;<br>open Genlex;;<br><br>let fprint_list pr ppf = function<br> | [] -> fprintf ppf "[]"<br> | x :: xs -><br> let f ppf = List.iter (fun x -> fprintf ppf ";@ %a" pr x) xs in<br> fprintf ppf "@[<1>[%a%t]@]" pr x f;; <br> <br>let lexer = make_lexer ["["; "]"; ";"] ;;<br><br>let rec parse_U = parser<br> | [< 'Kwd ";"; 'Int n; ns = parse_U >] -> n :: ns<br> | [< >] -> []<br> ;;<br><br>let parse_T = parser<br> | [< 'Int n; ns = ……
查看全文
发表于:2008-06-06 ┆
阅读(228)
┆
评论(2)
(转)Caml Introduction
<div> <p><img alt="Caml" src="http://archive.camlcity.org/archive/programming/icon-4.gif"><br></p> <p>Caml is a programming language which is very different from other, "classical"<a href="http://archive.camlcity.org/archive/programming/page-1.html#footnote1" name="textnote1"><font color="#0000ff">[1]</font></a> languages. While a program written in a classical languages consists mainly of <b>statements</b>, Caml programs are composed of <b>functions</b>. A statement takes its input values from the environment (such as variables), computes something, and stores the result again in the environment. To achieve more complex behaviour, you can execute one statement after another, or put your statements into loops. Functions are differ from this model, as there is no possibility to store something into the environment. </p> <p><img alt="An example" src="http://archive.camlcity.org/archive/programming/icon-1.gif"><br></p> <p>For example, to determine the biggest number of an array, e……
查看全文
发表于:2008-06-03 ┆
阅读(206)
┆
评论(0)