- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
以这个为例:
http://www.haskell.org/haskellwiki/99_questions/Solutions/32
(**) Determine the greatest common divisor of two positive integer numbers. Use Euclid's algorithm.
gcd' 0 y = y
gcd' x y = gcd' (y `mod` x) x
myGCD x y | x < 0 = myGCD (-x) y
| y < 0 = myGCD x (-y)
| y < x = gcd' y x
| otherwise = gcd' x y
The Prelude includes a gcd function, so we have to choose another name for ours. The function gcd' is a straightforward implementation of Euler's algorithm, and myGCD is just a wrapper that makes sure the arguments are positive and in increasing order.
A more concise implementation is:
myGCD :: Integer -> Integer -> Integer
myGCD a b
| b == 0 = abs a
| otherwise = myGCD b (a `mod` b)
最佳答案
.hs
文件中,例如C:\Haskell\MyGCD.hs
。 :cd
保存它的目录,然后使用:load
加载它:Prelude> :cd C:\Haskell
Prelude> :load MyGCD.hs
[1 of 1] Compiling Main ( MyGCD.hs, interpreted )
Ok, modules loaded: Main.
*Main> myGCD 12 10
2
:help
以获得更多信息,或参阅
Chapter 2: Using GHCi of the GHC User's Guide。
关于haskell - 如何在WinGHCi中运行此haskell程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8681200/
使用 WinGHCi 加载 *.hs 文件时,总是抛出异常。任何人都可以帮助我吗? 详情: 前奏> :l qsort.hs [1 of 1] 编译 Main(qsort.hs,已解释) ** 异常(e
因此,我尝试在 WinGHCi 中“:设置提示符“λ>””,它崩溃了,之后就无法再次启动(无响应)。我重新安装了 Haskell Platform,但它仍然无法启动(无响应)。 GHCi 在 cmd
我加载了两个模块(NecessaryModule1.hs 和 NecessaryModule2.hs,如 Haskell : loading ALL files in current director
我已经开始自学 Haskell,为此我安装了 The Haskell Platform对于 Windows。我现在正在使用 WinGHCi。我了解到它有命令 :cd 用于更改目录。但问题是,我怎么知道
为什么这个工作... Just.(+3) $ 6.7 Just $ truncate 8.9 ...但不是这个? Just.truncate $ 8.9 我尝试将截断解析为一个简单的 Double -
如何清除 WinGhci(Haskell 的 Windows IDE 之一)命令提示符和所有当前的“ session ”值? 最佳答案 您可以使用 :load没有参数来清除所有模块和绑定(bind)。
我是 Haskell 新手,遇到了这个臭名昭著的错误。 我已经查阅过这些链接: Haskell: parse error on input `|' Haskell parse error on inp
我对 n+k 模式有疑问。 我想启用它,但我不知道如何。 我在我的 .hs 文件的开头添加了 {-# LANGUAGE NPlusKPatterns #-},但它不起作用。 我也尝试在我的 ghci
我不知道如何让 WinGHCi 加载并编译我的 .hs 文件。 我有一个文件 C:\Users\Haskell\Source\hello.hs,仅包含以下行: main = putStrLn "Hel
当我输入 :edit 时,我想使用 Notepad++ 而不是 Notepad 作为 GHCi 编辑器调用.有谁知道如何做到这一点?我试过了 :set editor C:\Program Files
每次我双击 winghci.exe 时都会弹出一条错误消息 CreateGHCiProcess failed with failed with error 2。我假设安装没有成功完成设置环境变量,因为
我是一名优秀的程序员,十分优秀!