4

This question is related to this overflow post. The chosen answer there tells us that we can look up the source codes for built in functions on hackage site, for example curry.

What I'd like to ask for, however, is the location of the source codes of built in operations, including (+), (-), (*), (/=), ([...]), ([..|...]). The last two being "list constructor" and "list comprehensor" (I'm not sure if these are their standard name..).

The source codes of basic arithmetic operations like addition or multiplications are easier to find. However, for ([...]), ([..|...]) I simply have no clue where and how I can find them. Please point them out if you happen to know.

Micha Wiedenmann
  • 19,979
  • 21
  • 92
  • 137
Student
  • 400
  • 3
  • 10
  • 4
    The last two concerning lists are special syntactical constructs rather than operators. i.e. they are built into the compiler. If the reason you want the source code is just so you know what they are defined to do, you can find a specification for them in the Haskell report. – Potato44 Nov 19 '19 at 00:08
  • There are a couple papers about techniques for compiling list comprehensions for Haskell. – dfeuer Nov 19 '19 at 00:20
  • That is very interesting! I did not expect they are different than usual operators! What are the main difference between them and operators like `(+)`? Is it simply because that `[..]` has two components? – Student Nov 19 '19 at 00:22
  • I am very new to Haskell. @Potato44, would you mind pointing out where I can get that Haskell report? And are there even "higher operators" than `[..], [..|..]`? – Student Nov 19 '19 at 00:23
  • @dfeuer it is very good to know! I would very much like to hear about more. Any pointers or instances of such paper will be highly appreciated.. thank you! – Student Nov 19 '19 at 00:24
  • 2
    @Student the Haskell Report is [here](https://www.haskell.org/onlinereport/haskell2010/). Warning: it's written very formally, definitely not light reading! The section on lists is [here](https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-340003.7). – Robin Zigmond Nov 19 '19 at 00:35
  • The paper "A short cut to deforestation" by Gill et al explains one of the ways GHC does it (when optimization is enabled). That paper also points to ones by Wadler and by Augustsson (whom I hope will chime in with extra info). One or both of those describe the way GHC does it when optimizations are disabled. – dfeuer Nov 19 '19 at 20:16

1 Answers1

2

Here are the Haskell 98 report sections on lists, arithmetic sequences and list comprehensions. As for the actual implementation in the source code, I suggest downloading the repository and using grep to search around.

Links

MCH
  • 2,124
  • 1
  • 19
  • 34