<p>By entering <code>:i sqrt</code> using ghci, we can see that sqrt is</p>
<blockquote>
<p>-- Defined in ‘GHC.Float’</p>
</blockquote>
<p>A quick google shows that the source code repo is on <a href="https://gitlab.haskell.org/ghc/ghc" rel="noreferrer">https://gitlab.haskell.org/ghc/ghc</a>.</p>
<p>Entering <code>sqrt</code> in the search bar for the repository yields several pages of interesting results (including tests). From what I see, using <code>sqrt</code> includes calling the corresponding <code>sqrt</code> operation on a CPU level (check out the <a href="https://gitlab.haskell.org/ghc/ghc/-/blob/master/compiler/GHC/CmmToAsm/X86/CodeGen.hs" rel="noreferrer">x86 related code</a> as one example).</p>
<p>Of course, GHC is not the only implementation of Haskell, but at least within these realms, both terms are most often used as synonyms.</p>
<p>Edit: OP found the implementation detail with this approach in <a href="https://gitlab.haskell.org/ghc/ghc/-/blob/master/libraries/base/GHC/Float.hs" rel="noreferrer">https://gitlab.haskell.org/ghc/ghc/-/blob/master/libraries/base/GHC/Float.hs</a>, where <code>sqrt</code> is defined as follows:</p>
<pre><code>sqrt x              =  x ** 0.5
</code></pre>

CC BY-SA 4.0
2021-05-16T00:47:51.620Z
Thank you @Matthias Sieber 
From your instructions, I was delighted to find the following in the source code.
sqrt x  =  x ** 0.5
I found that I could substitute x ** 0.5 for sqrt which tells me a lot about Haskell.
Much thanks for your help
John Shearing
CC BY-SA 4.0
2021-05-15T23:06:48.403Z
2021-05-16T00:53:57.167Z
2021-05-16T00:53:57.167Z
Matthias Sieber
<p>API docs for the core libraries are maintained at haskell.org as well. There's an index link in the upper right where you can look up specific functions and then, on each module's documentation page, there are links to source code. For sqrt:</p>
<p><a href="https://downloads.haskell.org/%7Eghc/latest/docs/html/libraries/base-4.15.0.0/GHC-Float.html#v:sqrt" rel="nofollow noreferrer">https://downloads.haskell.org/~ghc/latest/docs/html/libraries/base-4.15.0.0/GHC-Float.html#v:sqrt</a></p>
<p>Also, bookmark this, the top-level of the latest API docs:</p>
<p><a href="https://downloads.haskell.org/%7Eghc/latest/docs/html/libraries/index.html" rel="nofollow noreferrer">https://downloads.haskell.org/~ghc/latest/docs/html/libraries/index.html</a></p>

CC BY-SA 4.0
2021-08-14T21:02:11.000Z
Great resource @dino. Much thanks
John Shearing
CC BY-SA 4.0
2021-08-10T15:50:36.577Z
2021-08-10T15:50:36.577Z
dino
<p>I am starting to learn Haskell and need to learn how to look things up.
Since I am studying a function that uses sqrt, I want to see how that was made in Haskell.
This is as much an exercise in using reference material as it is in seeing how the sqrt function works under the hood in Haskell. Any advice would be appreciated.</p>

<haskell>
How can I find the Haskell source code for the sqrt function?
# How can I find the Haskell source code for the sqrt function?

(Asked by: username_0 on 2021-05-15)

I am starting to learn Haskell and need to learn how to look things up.
Since I am studying a function that uses sqrt, I want to see how that was made in Haskell.
This is as much an exercise in using reference material as it is in seeing how the sqrt function works under the hood in Haskell. Any advice would be appreciated.

**Tags:** haskell

---

## 2 answers

### Answer by username_1 on 2021-05-15. Score: 8 | Accepted answer

By entering :i sqrt using ghci, we can see that sqrt is

-- Defined in ‘GHC.Float’

A quick google shows that the source code repo is on https://gitlab.haskell.org/ghc/ghc.
Entering sqrt in the search bar for the repository yields several pages of interesting results (including tests). From what I see, using sqrt includes calling the corresponding sqrt operation on a CPU level (check out the x86 related code as one example).
Of course, GHC is not the only implementation of Haskell, but at least within these realms, both terms are most often used as synonyms.
Edit: OP found the implementation detail with this approach in https://gitlab.haskell.org/ghc/ghc/-/blob/master/libraries/base/GHC/Float.hs, where sqrt is defined as follows:
sqrt x              =  x ** 0.5

> **Comments:**
> **username_0**: Thank you @Matthias Sieber  From your instructions, I was delighted to find the following in the source code. sqrt x  =  x ** 0.5 I found that I could substitute x ** 0.5 for sqrt which tells me a lot about Haskell. Much thanks for your help  

---

### Answer by username_2 on 2021-08-10. Score: 2

API docs for the core libraries are maintained at haskell.org as well. There's an index link in the upper right where you can look up specific functions and then, on each module's documentation page, there are links to source code. For sqrt:

[https://downloads.haskell.org/~ghc/latest/docs/html/libraries/base-4.15.0.0/GHC-Float.html#v:sqrt](https://downloads.haskell.org/%7Eghc/latest/docs/html/libraries/base-4.15.0.0/GHC-Float.html#v:sqrt)

Also, bookmark this, the top-level of the latest API docs:

[https://downloads.haskell.org/~ghc/latest/docs/html/libraries/index.html](https://downloads.haskell.org/%7Eghc/latest/docs/html/libraries/index.html)

> **Comments:**
> **username_0**: Great resource @dino. Much thanks  

---

