[SOLVED] Is `deriving` keyword a thing in PureScript?

I was editing a Emacs syntax highlight and noticed it has been highlighting deriving, because the code was derived from Haskell syntax highlight.

Now, I’ve never seen deriving used in PureScript (PS has derive instead). To be completely sure I decided to search over Github purescript files for the keyword, and… surprisingly, I did find code that is using it. However, I am not sure this code is valid, because the code looks more Haskellish despite being a .purs file.

So I decided to test it manually. So, given this working code:

module Main where

import Effect (Effect)
import Prelude

data ContourType = ExternalContour | InternalContour
derive instance eqContourType :: Eq ContourType

main :: Effect Unit
main = pure unit

I replace it to:

module Main where

import Effect (Effect)
import Prelude

data ContourType = ExternalContour | InternalContour deriving (Eq)

main :: Effect Unit
main = pure unit

…and I get error: Unknown type Eq. No complaints about the deriving though, the compiler simply stopped seeing Eq for some reason. So… what gives? Is it another instance of infamous PureScript compiler errors and the error should’ve been about the deriving instead? Or is the syntax valid but… perhaps requires some quirks or whatnot to work?

2 Likes

I agree that looks more like Haskell than PureScript. I wonder if their plan was to port it by trying to compile as PureScript and fix whatever errors popped up?

I checked the PureScript parser and there’s a derive keyword, but not deriving.

1 Like

Thank you! And also thank you for the file that can be used to check for keywords supported by the language!

1 Like

No problem!

I was also thinking about this more:

and realized that it’s treating Eq as a type instead of a class, so I added this:

data Eq = Eq
data ContourType = ExternalContour | InternalContour deriving Eq

and now it gives the error Type variable deriving is undefined. So it seems like it’s either checking the types right-to-left, or concrete before variable.

1 Like