From Scala to Haskell

Basics

Defining functions

Scala

`def triple(x: Int): Int = 3 * x`

Haskell

```
triple :: Int -> Int
triple x = 3 * x
```

Haskell (GHCi)

`triple :: Int -> Int; triple x = 3 * x`

Many tutorials use `let triple :: ...`

. There's no difference between those two notations in GHCi so it's up to you to decide .

Haskell (GHCi) - alternative

```
:{
triple :: Int -> Int
triple x = 3 * x
:}
```

Note the `:{`

and `:}`

in the first and last line. Besides of that it's the same as one would define the function in a source file.

???

Scala

`def compute: Int = ???`

Haskell

```
compute :: Int
compute = undefined
```

Function composition (andThen style)

Scala

```
// Given:
val toInt: String => Int = Integer.parseInt
val triple: Int => Int = x => 3 * x
// You can compose them:
(toInt andThen triple)("5")
// res: 15
```

Haskell

```
-- Given:
toInt :: String -> Int; toInt x = read x
triple :: Int -> Int; triple x = 3 * x
-- You can compose them:
import Control.Arrow
(toInt >>> triple) "5"
-- res: 15
```

Function composition (compose style)

Scala

```
> (triple compose toInt)("5")
// res: 15
```

Haskell

```
> (triple . toInt) "5"
-- res: 15
```