I don't understand why the below program fails to compile.
module Main where
import Prelude
import Effect (Effect)
import Effect.Console (log)
import Data.Generic.Rep (class Generic)
import Foreign.Generic (defaultOptions, genericEncodeJSON)
main :: Effect Unit
main = do
log "Hello sailor!"
newtype Foo = Foo {
x :: Int
, y :: Int
, z :: Array Bar
}
type Bar = {
a :: String
, b :: String
}
derive instance repGenericFoo:: Generic Foo _
fooToJSON :: Foo -> String
fooToJSON = genericEncodeJSON $ defaultOptions { unwrapSingleConstructors = true }
This is the output by the compiler
Compiling Main
Error found:
in module Main
at src/Main.purs line 27, column 13 - line 27, column 30
No type class instance was found for
Foreign.Class.Encode { a :: String
, b :: String
}
If Array is not used, then the program compiles
newtype Foo = Foo {
x :: Int
, y :: Int
, z :: Bar
}
type Bar = {
a :: String
, b :: String
}
why is it that genericEncodeJSON can't encode Bar if it's inside a container like Array or List?