[英]Calling a function in Agda
I have this code which is basically a hello world, with an addition function, it compiles and runs and outputs 'Hello, world 5!': 我有这段代码,它基本上是一个世界,它具有附加功能,它编译并运行并输出“ Hello,world 5!”:
open import Common.IO
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
-- how to call a function in agda i.e. '_+_(5, 4)' to get '9'
_+_ : ℕ → ℕ → ℕ
zero + m = m
suc n + m = suc (n + m)
main = putStrLn "Hello, world 5!"
How do I call my _+_
function? 如何调用
_+_
函数? My goal is to call _+_
with two arguments like _+_(3,4)
and get the program to output seven. 我的目标是使用
_+_(3,4)
类的两个参数来调用_+_
,并使程序输出七个。
My intuition says to replace the line ' main = putStrLn "Hello, world 5!"
我的直觉说,替换行'
main = putStrLn "Hello, world 5!"
' with something like ' putStrLn _+_(3,4)
' 像'
putStrLn _+_(3,4)
'
I'm new to Agda, and there aren't many examples online of working code. 我是Agda的新手,网上没有很多工作代码示例。 Can anybody get this function working by giving a practical code example?
任何人都可以通过给出实际的代码示例来使此功能正常工作吗?
Thanks! 谢谢!
open import Common.IO
open import Data.Nat using (ℕ; zero; suc)
open import Data.Integer using (ℤ; +_; show)
open import Data.String using (_++_)
_+_ : ℕ → ℕ → ℕ
zero + m = m
suc n + m = suc (n + m)
main = putStrLn ("Hello, world " ++ show (+ (3 + 4)) ++ "!")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.