4

Hi I'm building my own version of a GPU programming Haskell DSL which is called Accelerate. The question is about the the infixl declaration:

Here is the code snippet:

infixl 3 :.
data tail :. head = tail :. head
    deriving (Eq, Show)

I think this snippet is quite simple and clear, but when I was trying to load this into ghci, it failed:

It reported:

Illegal declaration of a type or class operator ‘:.’
      Use TypeOperators to declare operators in type and declarations

Do you have any idea about this problem? The ghc version I'm using is:

The Glorious Glasgow Haskell Compilation System, version 7.8.3

Thank you!

VELVETDETH
  • 314
  • 1
  • 8
  • 3
    It looks like you're trying to add a heterogeneous list type to haskell; That already exists in the HList package, and is also provided by GHC if you enable `DataKinds`. For example you could have a type `[Int,String,Int]` with kind `[*]`. – Cubic Nov 12 '14 at 16:45
  • @Cubic Actually I dont really understand the meaning of that sentence ... However, I agree with your idea that this one is a heterogeneous list. – VELVETDETH Nov 13 '14 at 05:14

1 Answers1

9

You need

{-# LANGUAGE TypeOperators #-}

in your source file. That is what the error message says. To use them in ghci, you have to enable there as well. See XTypeOperators extension doesn't work as pragma

Community
  • 1
  • 1
Franky
  • 2,339
  • 2
  • 18
  • 27
  • Oh it fixed! Thanks! But do you have any idea why this pragma should be there? I mean why ghc doesnt support it directly? – VELVETDETH Nov 12 '14 at 11:56
  • I did not read the [haskell 2010 report](https://www.haskell.org/onlinereport/haskell2010/), but I bet type operators are not included. Without pragmas, ghc complies to the standard. – Franky Nov 12 '14 at 12:06
  • Oh I see, so it's all about language standard... Thx – VELVETDETH Nov 12 '14 at 12:16
  • Where should infixr/infixl/infix declaration be put by convention? What if the operator is defined as part of a GADT? I see it could be put anywhere in the page? – CMCDragonkai Dec 28 '14 at 03:23