小编Md *_*vel的帖子

Haskell中的函数monad中的绑定是如何工作的?

从了解到一个哈克尔:http://learnyouahaskell.com/for-a-few-monads-more

函数的Monad实例是这样的:

instance Monad ((->) r) where  
    return x = \_ -> x  
    h >>= f = \w -> f (h w) w 
Run Code Online (Sandbox Code Playgroud)

我无法理解以下内容的输出:

import Control.Monad.Instances  

addStuff :: Int -> Int  
addStuff = do  
    a <- (*2)  
    b <- (+10)  
    return (a+b)
Run Code Online (Sandbox Code Playgroud)

addStuff 3返回19.书中说3作为参数传递给两者(*2) and (+10).怎么样?

h >>= f = \w -> f (h w) w,它似乎(h w)被绑定到a或b.那么,为什么6不被传递(+10)?

我的理解f这里的是,当(*2)h,f是最后2行addStuff.如果(+10)是 …

monads haskell

4
推荐指数
1
解决办法
122
查看次数

为什么显示 - "无法传递非平凡可复制类型的对象"?

您不必从头开始完成完整的代码.问题出在main里面的execl(..)语句中.代码是 -

#include <cstdio>
#include <iostream>
#include <cstring>
#include <unistd.h>
#include <sys/wait.h>
#include <vector>

#define li long int

using namespace std;


char TypedCommandInTerminal[1001];
vector <string> ValidCommands,TypedCommand;


void ShowTerminal()
{
    cout<<"User:$ ";
    gets(TypedCommandInTerminal);
}


void PushCommands()
{
    ValidCommands.push_back("mkdir");
}


void GetCommandIntoVector()
{
    TypedCommand.clear();

    char *p = strtok(TypedCommandInTerminal," ");

    while(p)
    {
        TypedCommand.push_back(p);
        p = strtok(NULL," ");
    }
}

bool MatchCommand(string Command)
{
    li i;

    for(i=0;i<ValidCommands.size();i++)
    {
        if(ValidCommands[i].compare(Command)==0)
        {
            return true;
        }
    }
    return false;
}



int main()
{
    int status;
    string StoredCommand; …
Run Code Online (Sandbox Code Playgroud)

c++ linux os.execl

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

c++ ×1

haskell ×1

linux ×1

monads ×1

os.execl ×1