首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在WinGHCi中运行这个haskell程序?

如何在WinGHCi中运行这个haskell程序?
EN

Stack Overflow用户
提问于 2011-12-30 23:46:33
回答 1查看 5.1K关注 0票数 5

以此为例:http://www.haskell.org/haskellwiki/99_questions/Solutions/32

代码语言:javascript
运行
复制
(**) 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)

如何在WinGHCi中测试它?运行haskell程序的步骤/工作流程是什么?

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-30 23:52:54

  1. 将代码保存在某个.hs文件中,例如C:\Haskell\MyGCD.hs.
  2. Start WinGHCi,然后转到使用:cd保存代码的目录,然后使用:load加载代码:

Prelude> :cd C:\Haskell Prelude> :load MyGCD.hs 1 of 1编译Main ( MyGCD.hs,解释) Ok,模块已加载:Main。

  • 现在您可以使用以下函数:

*Main> myGCD 12 10 2

有关详细信息,请键入:help,或查看Chapter 2: Using GHCi of the GHC User's Guide

票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8681200

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档