:p f : Float --o Float f = llam x. x f 1.0 > 1.0 :t llam x:Float. x * x > Linearity error: pattern spent twice: [x] > > :t llam x:Float. x * x > ^^ :t llam x:Float. x * 2.0 > (Float --o Float) :t llam x:Float. 2.0 * x > (Float --o Float) :t llam x:Float. llam y:Float. x * y > (Float --o (Float --o Float)) :t llam x:Float. (llam y. y) x > (Float --o Float) :t llam x:Float. (\y. y) x > Linearity error: nonlinear function consumed linear data: [x] > > :t llam x:Float. (\y. y) x > ^^^^^^^^^^^^^^^^^^^^^^ :t llam x:Float. (1.0, x) > (Float --o (Float, Float)) :t llam x:Float. (x, 1.0) > (Float --o (Float, Float)) :t llam x:Float. (x, x) > (Float --o (Float, Float)) :t llam x:Float. 1.0 + x > (Float --o Float) :t llam x:Float. x + 1.0 > (Float --o Float) :t llam x:Float. x + x > (Float --o Float) :t llam x:Float. 1.0 * x > (Float --o Float) :t llam x:Float. x * 1.0 > (Float --o Float) :t llam x:Float. x * x > Linearity error: pattern spent twice: [x] > > :t llam x:Float. x * x > ^^ :t llam x:Float. y = x x + y > (Float --o Float) :t llam x:Float. y = x; y * x > Linearity error: pattern spent twice: [x] > > y = x; y * x > ^^ :t llam (x, y). x + y > ((Float, Float) --o Float) :t llam (x, y). x * y > Linearity error: pattern spent twice: [x] > > :t llam (x, y). x * y > ^^ :p (llam x. x + x) 1.0 > 2.0 :p (llam x. x * 3.0) 1.0 > 3.0 :t llam x. x * 0.0 > (Float --o Float) :t llam x. 0.0 * x > (Float --o Float) :t llam x:Float. 0.0 * 0.0 > (Float --o Float) :t llam x. x + 0.0 > (Float --o Float) :t llam x. 0.0 + x > (Float --o Float) :t llam x:Float. 0.0 + 0.0 > (Float --o Float) :t llam x. (0.0 + x) + 0.0 > (Float --o Float) :t llam x. (0.0 + x) + 1.0 > (Float --o Float) :t llam x. 0.0 + (x + 1.0) > (Float --o Float) :t llam y. llam x. (x + 0.0) + (y + 0.0) > (Float --o (Float --o Float)) :t llam y. llam x. (x * 0.0) + y > (Float --o (Float --o Float)) :t llam x:Float. () > (Float --o ()) nonLinFun : Float -> Float nonLinFun x = x linFun : Float --o Float linFun x = x eatsLin : (Float --o Float) -> Bool eatsLin f = True eatsNonLin : (Float -> Float) -> Bool eatsNonLin f = True :t eatsLin linFun > Bool :t eatsLin nonLinFun > Type error: > Expected: (Float --o Float) > Actual: (Float -> Float) > In: nonLinFun > > :t eatsLin nonLinFun > ^^^^^^^^^ :t eatsNonLin linFun > Type error: > Expected: (Float -> Float) > Actual: (Float --o Float) > In: linFun > > :t eatsNonLin linFun > ^^^^^^ :t eatsNonLin nonLinFun > Bool :t eatsLin (\x. linFun x) > Bool :t eatsLin (\x. nonLinFun x) > Linearity error: nonlinear function consumed linear data: [x] > > :t eatsLin (\x. nonLinFun x) > ^^^^^^^^^^^^^^^ :t eatsNonLin (\x. linFun x) > Bool :t eatsNonLin (\x. nonLinFun x) > Bool :t \f. (eatsLin f, eatsNonLin f) > Type error: > Expected: (Float -> Float) > Actual: (Float --o Float) > In: f > > :t \f. (eatsLin f, eatsNonLin f) > ^ linFstArg : Float --o Float -> Float linFstArg x y = x / y linUnary : Float --o Float linUnary x = linFstArg x 1.0 -- Nonlinear because of defaulting rules :t f x = x + x f > (Float -> Float) f1 : Float --o Float f1 x = %runReader(x, \r. y = %ask(r) z = %ask(r) y + z) f2 : Float --o Float f2 x = %runReader(x, \r. y = %ask(r) z = %ask(r) y * z) > Linearity error: pattern spent twice: [x] > > y * z) > ^^ f3 : Float --o Float f3 x = y = snd $ %runWriter(\w. _ = %tell(w, x) _ = %tell(w, x) ()) y + x f2 : Float --o Float f2 x = y = snd $ %runWriter(\w. _ = %tell(w, x) _ = %tell(w, x) ()) y * x > Linearity error: pattern spent twice: [x] > > y * x > ^^