Quantcast
Channel: CSDN博客推荐文章
Viewing all articles
Browse latest Browse all 35570

软件设计师的数学之路(1)-离散数学(1)-走近haskell(3)

$
0
0

本博客所有内容是原创,未经书面许可,严禁任何形式的转载。

http://blog.csdn.net/u010255642

在haskell中可以使用if条件语句,和其它语言一样,但是else部分必须有,不能省略

我们定义一下自己的求绝对值的函数,将函数定义在mytest.hs中

myabs x = if x>0 
           then x
           else -x

然后,加载并运行

*Main> :l f:\pro\mytest.hs
[1 of 1] Compiling Main             ( F:\pro\mytest.hs, interpreted )
Ok, modules loaded: Main.

*Main> myabs 11

11
*Main> myabs (-11)
11
*Main> myabs (-12)
12
*Main>
作者:u010255642 发表于2013-4-28 16:21:08 原文链接
阅读:10 评论:0 查看评论

Viewing all articles
Browse latest Browse all 35570

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>