2015-10-09 11 views
5

Próbuję użyć biblioteki aeson dla json parsowania i śledzę dokumentację To jest mój kod teraz:nieoczekiwane ostrzeżenie Haskell ajzon. Brak wyraźnego realizacja dla „toJSON”

{-# LANGUAGE OverloadedStrings #-} 
{-# LANGUAGE DeriveGeneriC#-} 

import Data.Aeson as Ae 
import Data.Text as T 
import qualified Data.ByteString.Lazy as BS 
import GHC.Generics 

data Episode = Episode { season :: Int 
         , epNum :: Int 
         } deriving (Show, Generic) 

data Series = Series { title  :: !T.Text 
        , curEpisode :: Episode 
        } deriving (Show, Generic) 

instance FromJSON Episode 
instance ToJSON Episode   -- Warning here 
instance FromJSON Main.Series 
instance ToJSON Main.Series  -- Warning here 

Problemem jest to, że mam te dwa ostrzeżenia.

src\Main.hs:21:10: Warning: 
    No explicit implementation for 
     `toJSON' 
    In the instance declaration for `ToJSON Episode' 

src\Main.hs:22:10: Warning: 
    No explicit implementation for 
     `toJSON' 
    In the instance declaration for `ToJSON Main.Series' 

nie mogę zrozumieć, dlaczego tak się dzieje

EDIT:

GHC Wersja: 7.10.2

wersja ajzon: 0.10.0.0 (najnowsza)

+0

Dziwne. Jaka jest wersja 'aeson'? Jaką wersję GHC? – dfeuer

+0

@dfeuer Rzeczywiście dziwne. Edytowałem post, aby uwzględnić te informacje! – TheCrafter

Odpowiedz

5

mogę obejść ostrzeżeń w ten sposób:

instance FromJSON Episode 
instance ToJSON Episode where 
    toJSON = genericToJSON defaultOptions 
instance FromJSON Main.Series 
instance ToJSON Main.Series where 
    toJSON = genericToJSON defaultOptions 

wciąż nie wiem, dlaczego istnieją ostrzeżenia, ale widziałem już zgłoszenie błędu: on github.

+2

Ah ... wygląda na to, że pomyłkowo dodali oni '' - # MINIMAL toJSON # -} 'do definicji klasy' ToJSON'. Ups. Zajmują się także ogólnymi sprawami, używając modułu pełnego instancji osieroconych, co jest dość poważnie brzydkie. – dfeuer

+0

@dfeuer Tak, masz rację. – TheCrafter

Powiązane problemy