문제

I am writing a function like this.

func :: IO()
func = putStr print "func = putStr print"

I know it is incorrect but the idea is I want the putStr applied onto the string then print applied onto the same string "fun = .." so that the output would be:

func = putStr print "func = putStr print"

which is the same as my function definition. Thanks

도움이 되었습니까?

해결책

유형 인수의 조합 당 하나의 필드를 정말로 얻을 것이라는 것을 알고있는 한 일반 유형의 정적 필드를 갖는 것이 좋습니다.내 추측은 r #이 당신이 그것을 알지 못하는 경우를 대비하여 당신을 경고하는 것입니다.

여기의 예가 있습니다 :

using System;

public class Generic<T>
{
    // Of course we wouldn't normally have public fields, but...
    public static int Foo;
}

public class Test
{
    public static void Main()
    {
        Generic<string>.Foo = 20;
        Generic<object>.Foo = 10;
        Console.WriteLine(Generic<string>.Foo); // 20
    }
}
.

보시다시피, Generic<string>.FooGeneric<object>.Foo의 다른 필드입니다. 이들은 별도의 값을 유지합니다.

다른 팁

I'm not sure where you are going with the "without using >>" part (if that's really the point use do-notation), but you can easily write a helper function that applies two functions in sequence to the same input:

tee f g s = f s >> g s

func = tee putStr print "..."

Also, to just avoid repeating the string, a local variable with let or where would probably be the easiest:

let s = "..."
in  putStr s >> print s

You could do it like this:

doActions str actions = mapM_ ($ str) actions
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top