Functions on first class functions

I need a source for examples of, or rules for, defining higher type functions.

If T is a defined func type I want to be able to define func’s of type
T/T or T/TT. ie func(T) T and func(T T ) T.

I’d greatly appreciate any references or examples or hints.

Thanks for your time.

Charlie Davis

I don’t understand your notation and hence what you’re asking for. Can you be more concrete? Generally speaking, function types are just types and you declare functions to accept them like any other type.

If you are asking if you can express something like haskells map :: (a -> b) -> [a] -> [b], then no, you can’t.

There are no typevariables or generics or similar in Go.

There are some language constructs (like append) which appear to be functions with a generic type (append([]Type, Type...) but those are not functions, that are part of the language and treated in a special way.

I’ll try to be more clear.
Suppose I define a type

type kind func(int) bool

defining instances of this type is easy. Next I define

type monadicOperator func(kind) kind

So far so good.

But next I wish to define instances of the type monadicOperator, for example a function non that takes the kind p into its complement kind non( p ), so that

non( p )(i) == true iff p(i) == false

I hope this is clearer.

Hacked down in less than 5 minutes, so I do not see your problem:


I extended my example to show, that you can pass non(is_zero) through non again, to get the original function back (in this case at least):

1 Like

Perfect. Thank you.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.