faylang / fay

A proper subset of Haskell that compiles to JavaScript
https://github.com/faylang/fay/wiki
BSD 3-Clause "New" or "Revised" License
1.29k stars 89 forks source link

Impossible to use deriving (Show) with fay-text? #348

Closed emmanueltouzery closed 11 years ago

emmanueltouzery commented 11 years ago

I didn't manage to get autoderivation of "Show" to work as expected:

{-# LANGUAGE NoImplicitPrelude, OverloadedStrings, RebindableSyntax #-}

import Fay.Text (Text, fromString)
import qualified Fay.Text as T
import Prelude

data MainAction = Primary T.Text
          | Danger T.Text
    deriving (Show)
$fay --package fay-text FayShow.hs
fay: ghc: 
FayShow.hs:9:19:
    Couldn't match expected type `String' with actual type `Text'
    Expected type: [Char] -> String
      Actual type: String -> Text
    In the first argument of `base:GHC.Show.showString', namely
      `"Primary "'
    In the first argument of `(base:GHC.Base..)', namely
      `(base:GHC.Show.showString "Primary ")'

This used to work fine when using plain String. How to achieve that with the latest master, if at all possible?

bergmark commented 11 years ago

Are you sharing this type between server and client? Otherwise there is currently no point in having Show instances.

The issue occurs because of RebindableSyntax+Fay.Text.fromString, this seems to solve it but I can't tell you why =o

{-# LANGUAGE NoImplicitPrelude, OverloadedStrings, RebindableSyntax #-}

import Fay.Text (Text, fromString)
import qualified Fay.Text as T
import Prelude

data MainAction = Primary T.Text
          | Danger T.Text

instance Show MainAction
emmanueltouzery commented 11 years ago

OK I understand so since we switched to Text this deriving (Show) is a pattern to avoid in Fay programs, and "print" and "show" will anyway work as expected even without implementing the typeclass. I can live with that :-)

I thought maybe you overlooked this..

Thank you!

bergmark commented 11 years ago

Show never did anything actually, we might have had the constraint on print at some point, but that would have been loong ago :)