#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Options

# Question 1.1 - Functions in mathematics and Haskell

edited January 19

Suppose $$f : Int \to Int$$ sends an integer to its square, $$f(x) := x^2$$ and that $$g : Int \to Int$$ sends an integer to its successor, $$g(x) := x+ 1$$.

(a) Write $$f$$ and $$g$$ in Haskell, including their type signature and their implementation.

(b) Let $$h := f◦g$$. What is $$h(2)$$?

(c) Let $$i := f ; g$$. What is $$i(2)$$?

• Options
1.
Comment Source:My answer: https://paste.sr.ht/%7Eleif/42cc64b988ce44a69dbfc16ab88a0c37237665ba
• Options
2.

what is meant by $f;g$?

Comment Source:what is meant by $f;g$?
• Options
3.
edited January 18

@HanifBinAriffin: $$f;g$$ means apply $$f$$, then apply $$g$$. It's the opposite order of operations than $$f \circ g$$, which means apply $$g$$ then $$f$$.

In $$f;g$$ the data flows "forwards" from left to right (forward only because English reads from left to right), whereas in $$f \circ g$$ it flows "backwards" from right to left.

Comment Source:@HanifBinAriffin: \$$f;g\$$ means apply \$$f\$$, then apply \$$g\$$. It's the opposite order of operations than \$$f \circ g\$$, which means apply \$$g\$$ then \$$f\$$. In \$$f;g\$$ the data flows "forwards" from left to right (forward only because English reads from left to right), whereas in \$$f \circ g\$$ it flows "backwards" from right to left.