﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-银色月光下</title><link>http://www.cppblog.com/lichking/</link><description>漫漫长夜</description><language>zh-cn</language><lastBuildDate>Tue, 14 Apr 2026 23:06:21 GMT</lastBuildDate><pubDate>Tue, 14 Apr 2026 23:06:21 GMT</pubDate><ttl>60</ttl><item><title>怎么表示同一对象</title><link>http://www.cppblog.com/lichking/archive/2014/06/10/207239.html</link><dc:creator>lichking</dc:creator><author>lichking</author><pubDate>Mon, 09 Jun 2014 16:43:00 GMT</pubDate><guid>http://www.cppblog.com/lichking/archive/2014/06/10/207239.html</guid><wfw:comment>http://www.cppblog.com/lichking/comments/207239.html</wfw:comment><comments>http://www.cppblog.com/lichking/archive/2014/06/10/207239.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lichking/comments/commentRss/207239.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lichking/services/trackbacks/207239.html</trackback:ping><description><![CDATA[一些例子，<br /><br />我们创建符号表，当前的context的string_key去query一个对象，<br /><br />对同一对象的可表示为这个对象的引用和同一对象相关的数据结构封装得到的一个smart_ptr，<br /><br />&nbsp; &nbsp; 如在shared_ptr里，我们用对象&amp;引用计数 指针，可得到同一对象，和同一对象的计数情况，<br /><br />&nbsp; &nbsp; 可用对象&amp; 对象容器//，得到同一对象，并容易遍历所有同一对象，<br /><br />&nbsp; &nbsp; 函数里变量对象，{name, type, function}, {argument idx|var}, {list}<br /><br /><br /><img src ="http://www.cppblog.com/lichking/aggbug/207239.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lichking/" target="_blank">lichking</a> 2014-06-10 00:43 <a href="http://www.cppblog.com/lichking/archive/2014/06/10/207239.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>谈谈类型</title><link>http://www.cppblog.com/lichking/archive/2014/05/02/206800.html</link><dc:creator>lichking</dc:creator><author>lichking</author><pubDate>Fri, 02 May 2014 13:54:00 GMT</pubDate><guid>http://www.cppblog.com/lichking/archive/2014/05/02/206800.html</guid><wfw:comment>http://www.cppblog.com/lichking/comments/206800.html</wfw:comment><comments>http://www.cppblog.com/lichking/archive/2014/05/02/206800.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lichking/comments/commentRss/206800.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lichking/services/trackbacks/206800.html</trackback:ping><description><![CDATA[<strong>类型</strong>可以从两个角度去理解，<br />1. 在编程语言里，类型保证了在表达式和函数里怎么保证程序的正确.<br />比如：在应用 add时，保证参数是 int, 在concat里是 string;<br /><br />2. 对数据的定义，我们如何表示一个数据是什么，如何去解析，去使用它,<br />比如说，数据库里person类型里定义，(person.name，person.age);<br /><br />让我们来归纳一下，在应用中我们常见类型，(不太严格的方式，使用类haskell的语法)<br />.<strong>基本类型</strong>，<br />bool, int, string<br /><br />.复合类型<br />..<strong>组合</strong><br />&nbsp; &nbsp; struct/tuple, <br />&nbsp; &nbsp; example: person: (age:int, name:string)<br />..<strong>枚举</strong><br />&nbsp; &nbsp; (union+enum):<br />&nbsp; &nbsp; example: <br />&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;week: (mon | tus | wen | thu | fri | sat | sun)<br />&nbsp; &nbsp; &nbsp; &nbsp;input: (mouse: x:int, y:int) | (key: keycode:int)<br /><br />(tips: 这里我们怎么表示 <br />&nbsp; &nbsp; &nbsp;1. array int[3], &nbsp;arr3 := (int, int, int)<br />&nbsp; &nbsp; &nbsp;2. list&lt;int&gt;, &nbsp;list_int := (int: value, next: list_int) | end<br />&nbsp; &nbsp; &nbsp;3. binary_tree: left: (value:int, left:binary_tree, right:binary_tree) | leaf : int<br />&nbsp; &nbsp; &nbsp;可见，到这里，我们已经可以表达一般的<strong>数据结构</strong>.<br /><br />.<strong>函数类型</strong><br />&nbsp; &nbsp;type_1-&gt;type_2<br />&nbsp; &nbsp;example: <br />&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;(定义了内置的一些函数)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;length : string-&gt;int<br />&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br />..<strong>高阶函数类型</strong><br />&nbsp; &nbsp; type_1-&gt;(type_2-&gt;type_1)<br />&nbsp; &nbsp; example:&nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; encode: (code_method:int-&gt;(src:string-&gt;dst:string) )<br />&nbsp; &nbsp; (很多编程语言里的闭包)<br /><br />..(如果我们加上(表达式/apply<strong>,&nbsp;</strong>函数求值)<strong>，</strong>就是一个编程语言了) &nbsp;&nbsp;<br /><br />..<strong>模板</strong><br />&nbsp; &nbsp; Type &lt;type_args&gt; := &lt;type expression&gt;<br />&nbsp; &nbsp; example:<br />&nbsp; &nbsp; &nbsp; &nbsp; list T := (value: T, next: list T) | null<br />&nbsp; &nbsp; &nbsp; &nbsp; (像是c++里的 list&lt;T&gt; ) &nbsp;&nbsp;<br /><br />&nbsp;<br />谈谈类型的关系，子类型如何表示在这个系统里呢，class Derived : base<br />组合和继承是同态的，继承可以认为是组合的一个语法糖，因此它也包括在 struct 类型关系里，<br /><br />但显然，类型转换这样的语法糖是很方便的.<br /><br />实用上，应该提供原生的，array&lt;T&gt;, option&lt;T&gt;, (in proto_buffer) .<br /><br />更强的类型系统，是 <a href="http://en.wikipedia.org/wiki/Dependent_type"><strong style="color: #3366ff;">depend type</strong></a>, 当然已经超过我能讨论的了.<strong><br /></strong><img src ="http://www.cppblog.com/lichking/aggbug/206800.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lichking/" target="_blank">lichking</a> 2014-05-02 21:54 <a href="http://www.cppblog.com/lichking/archive/2014/05/02/206800.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于API 设计</title><link>http://www.cppblog.com/lichking/archive/2013/07/28/202176.html</link><dc:creator>lichking</dc:creator><author>lichking</author><pubDate>Sat, 27 Jul 2013 17:04:00 GMT</pubDate><guid>http://www.cppblog.com/lichking/archive/2013/07/28/202176.html</guid><wfw:comment>http://www.cppblog.com/lichking/comments/202176.html</wfw:comment><comments>http://www.cppblog.com/lichking/archive/2013/07/28/202176.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lichking/comments/commentRss/202176.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lichking/services/trackbacks/202176.html</trackback:ping><description><![CDATA[怎样才是好的API设计，让我们先来想想什么是糟糕的API,<br /><br />糟糕的API有很多你不理解的参数<br />糟糕的API设计让你维护很多状态<br /><br />第一种情况，查各种参数意义，并需要例子参考之，这些例子作为你使用的模板，<br />第二种情况，你call 一个个api的流程，你写很多状态处理，大多数情况大同小异，也作为模板，<br /><br />模板就是在体现在代码里的一些选项参数，结构参数，所以能被进一步抽象，<br /><br />我们不是有了 interface, function，那么就在API的设计体现出这种模式化，<br />比如说 IO的C的API，<br />open/close, read/write, iostate,&nbsp;<br />你容易忘记在某个异常里close, 你可能在某个状态时没有调用对API，read mode下call write, 在IO关闭后继续读写，还有考虑，读异常，写异常发生时，你要做的事情<br /><br />那么如下设计是否更加结构化了呢<br /><div>withfile_read(fn, option, reader:(Either String Ex)-&gt;() &nbsp;);</div><div>withfile_write(fn, option, writer: ()-&gt;(String, &nbsp;Ex-&gt;() &nbsp;) &nbsp;);</div><img src ="http://www.cppblog.com/lichking/aggbug/202176.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lichking/" target="_blank">lichking</a> 2013-07-28 01:04 <a href="http://www.cppblog.com/lichking/archive/2013/07/28/202176.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>2013/7/8</title><link>http://www.cppblog.com/lichking/archive/2013/07/08/201602.html</link><dc:creator>lichking</dc:creator><author>lichking</author><pubDate>Sun, 07 Jul 2013 17:07:00 GMT</pubDate><guid>http://www.cppblog.com/lichking/archive/2013/07/08/201602.html</guid><wfw:comment>http://www.cppblog.com/lichking/comments/201602.html</wfw:comment><comments>http://www.cppblog.com/lichking/archive/2013/07/08/201602.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lichking/comments/commentRss/201602.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lichking/services/trackbacks/201602.html</trackback:ping><description><![CDATA[我希望能好好地学一下haskell了<img src ="http://www.cppblog.com/lichking/aggbug/201602.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lichking/" target="_blank">lichking</a> 2013-07-08 01:07 <a href="http://www.cppblog.com/lichking/archive/2013/07/08/201602.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>