簡體   English   中英

似乎無法正確編寫函數

[英]can't seem to get composing functions right

我在ML中編寫函數時遇到問題

local
    fun add(g:int->int,f:int->int,m:int,x:int,sum:int):int=
    if m>x then sum
           else add(g,g o f,m+1,x,sum+(g f x))             
in
    fun sum f g x=
    if x=0 then f x
           else add(g,g o f,1,x,f x)  
end;

現在,我想做的基本上是f(x)+ g(f(x))+ g(g(f(x)))+ ... + g ^ x(f(x)),但我無法做到正確。 我不斷收到錯誤,表明操作數和運算符不同意go f。 有人可以指出我做錯了什么,也許我該如何解決?

fun sum f g x

是功能的給定簽名,因此我無法更改。

我不認為錯誤是在gof ,它在gfx 那不進行類型檢查,因為g不是兩個參數的函數。 您是說g(fx)嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM