stylish-haskell
stylish-haskell copied to clipboard
Parse error in the absence of -XFlexibleContexts
The following piece of code (essentially a modified snippet from Thinking with Types by Sandy Maguire) compiles and runs fine (GHC 8.6.3 on macOS 10.14.2 installed with Stack using lts-13.4).
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleInstances #-}
module Main where
import Data.Kind ( Type )
main :: IO ()
main = do
let a = True :# "True" :# HNil
b = a
print (a == b)
data HList (ts :: [Type]) where
HNil :: HList '[]
(:#) :: t -> HList ts -> HList (t ': ts)
infixr 5 :#
instance Eq (HList '[]) where
HNil == HNil = True
instance (Eq t, Eq (HList ts)) => Eq (HList (t ': ts)) where
(a :# as) == (b :# bs) = a == b && as == bs
However, stylish-haskell (0.9.2.1) won’t parse it unless -XFlexibleContexts is active:
$ stylish-haskell ../bug/src/Main.hs
Language.Haskell.Stylish.Parse.parseModule: could not parse ../bug/src/Main.hs: ParseFailed (SrcLoc "<unknown>.hs" 28 1) "Malformed context: FlexibleContexts is not enabled"
Adding the pragma {-# LANGUAGE FlexibleContexts #-}
makes stylish-haskell behave as expected, but it’s unsatisfying.
Given this comment, I realize that the issue may not be with stylish-haskell itself. I’ll investigate.
I have tested compiling stylish-haskell against haskell-src-exts-1.21.0, but the bug remains. If I find the time I will dig into haskell-src-exts directly.
The following config file will work around this and related issues, without forcing a workaround to your main haskell source code:
steps:
- simple_align: {}
- imports: {}
- language_pragmas: {}
- trailing_whitespace: {}
language_extensions:
- FlexibleContexts # stylish-haskell bug, see jaspervdj/stylish-haskell#230
- MultiParamTypeClasses # stylish-haskell bug, see jaspervdj/stylish-haskell#103 and haskell-suite/haskell-src-exts#304