haskell / haskell/stylish-haskell

Parse error in the absence of -XFlexibleContexts

Open
#230 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
1k
Forks
153
PR merge metrics
No merged PRs in 30d

Description

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).

```haskell
{-# 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 ".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](https://github.com/jaspervdj/stylish-haskell/issues/45#issuecomment-30211961), I realize that the issue may not be with stylish-haskell itself. I’ll investigate.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.