Showing posts with label z9825| Inferred. Show all posts
Showing posts with label z9825| Inferred. Show all posts

Recursive Function

// PS:43, psn > a15 > 160
// Scala type inference cannot infer the return type of recursive
// function

// @tailrec Annotation can be used to check tail-call optimization

Semicolon(;) : The expression delimiter

An expression can be delimited using semicolon(;)
scala> val no:Int = 0;
no: Int = 0

scala> val no2:Float = 0; val no3:Double = 0;
no2: Float = 0.0
no3: Double = 0.0

An end of line is inferred to be semicolon(and therefore end of expression) unless otherwise the end of line has one of these characters ; equalto(=), Curly Brace({), Comma(,), Periods(.) or Operators(+, -, etc...). These characters at the end of the line denotes a continuation of the expression
scala> def fn1() =
     |     println("Multiline expression using equal to")
fn1: ()Unit

scala>
     | def fn2() = {
     |     println("Multiline expression using Curly brace")
     | }
fn2: ()Unit

scala> def fn3(arg1: Int,
     |         arg2: Float) =
     |     println("This is " +
     |             "another example")
fn3: (arg1: Int, arg2: Float)Unit

PS : 
The Return type of a function is called as Result Type (#m:68) in Scala
Also note, in function type 'fn2: ()Unit', empty Round brackets represents a function that takes no arguments