haskell / stylish-haskell

Haskell code prettifier
Other
986 stars 150 forks source link

UnicodeSyntax #418

Open id-ekaagr opened 2 years ago

id-ekaagr commented 2 years ago
{-# language UnicodeSyntax #-}

module Main where

import Prelude qualified as A

data Term a where
 Lit :: A.Int -> Term A.Int
 Succ :: Term A.Int -> Term A.Int
 IsZero :: Term A.Int -> Term A.Bool
 If :: Term A.Bool -> Term a -> Term a -> Term a
 Pair :: Term a -> Term b -> Term (a, b)

Here no instance of -> gets converted to .

id-ekaagr commented 1 year ago

Example :

{-# language UnicodeSyntax #-}

module Main where

import Prelude qualified as A

data Detail
 = Detail
 { id             :: String
 , name           :: String
 }
 deriving (Show)

In any record :: is never converted to where UnicodeSyntax is enabled.

Lev135 commented 1 year ago

Yes, currently, as far as I can see, only three features are supported: ::, ->, => in function type signature. I've implemented replacement of -> in GADTs in my fork, I'll try to cover at least all the GADTs issues (i. e. => and :: in GADT declaration) and then open a pull request. However, it isn't likely to be very soon, so if someone else will be able to contribute this, it would be great

id-ekaagr commented 1 year ago

Thanks for addressing this.

Until it's fixed, I'm using this VS Code extension: https://marketplace.visualstudio.com/items?itemName=adamwalzer.code-replacer

With these settings:

 "codeReplacer.includeDefaultRules": false,
 "codeReplacer.replaceOnSave": true,
 "codeReplacer.rules": {
  "hs": {
   " -< ": " ⤙ ",
   " -<< ": " ⤛ ",
   " -> ": " → ",
   " :: ": " ∷ ",
   " \\(\\| ": " ⦇ ",
   " \\[\\| ": " ⟦ ",
   " \\* ": " ★ ",
   " \\|\\) ": " ⦈ ",
   " \\|\\] ": " ⟧ ",
   " <- ": " ← ",
   " => ": " ⇒ ",
   " >- ": " ⤚ ",
   " >>- ": " ⤜ ",
   " forall ": " ∀ "
  }
 },
 "codeReplacer.statusBarText": "`$(telescope) ${codes.length} code segments to replace`",
Lev135 commented 1 year ago

Thanks very much for this list! It was very helpful for me. I had a problem to find where >- and >>- are used. If you have an example, please, share it in the comments to PR or add it to it by yourselves.