Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use 'aux' keyword in Haskell

Tags:

scope

haskell

Okay, I've looked on about 4-5 websites that offered to teach Haskell and not one of them explained the keyword aux. They just started using it. I've only really studied Java and C (never saw it in either if it exists), and I've never really encountered it before this class that I'm taking on Haskell. All I can really tell is that it provides the utility to create and store a value within a function. So what exactly does it do and how is it properly used and formatted? In particular, could you explain its use while recursing? I don't think that its use is any different, but just to make sure I thought I would ask.

like image 287
Troy Paragon Burtin Avatar asked Sep 05 '25 17:09

Troy Paragon Burtin


1 Answers

There is no keyword aux, my guess is this is just the name they used for a local function.

Just like you can define top-level values:

myValue = 4

or top-level functions:

myFunction x = 2 * x

you can similarly define local values:

myValue =
    let myLocalValue = 3 in
    myLocalValue + 1

-- or equivalently:
myValue = myLocalValue + 1
    where myLocalValue = 3

or a local function:

myValue =
    let myLocalFunction x = 2 * x in
    myLocalFunction 2

-- or equivalently:
myValue = myLocalFunction 2
    where myLocalFunction x = 2 * x

Your teacher simply named the local function aux instead of myLocalFunction.

like image 135
Tarmil Avatar answered Sep 07 '25 17:09

Tarmil