python - Haskell: How can we define a general purpose logging wrapper function? -
suppose want have function log
accepts function, wraps around function , logging input/output of function. pseudo-code:
func log(func f, input) { var output = f(input); log_data(input); log_data(output); }
how possible in haskell? how can define general function pointer general list of inputs in function call? similar python decorators loggin.
to more specific, want general mechanism add logging input/output of functions in application. of course possible adding 2 lines of code each function log input , output want general-purpose solution works functions input.
a sample logging decorator in python:
def logged(f): @wraps(f) def wrapped(*args, **kwargs): print "logging..." r = f(*args, **kwargs) print "call finished" return r return wrapped @logged def myfunc(myarg): print "my function", myarg return "return value"
Comments
Post a Comment