default rules?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{-# LANGUAGE OverloadedStrings, FlexibleInstances, ExtendedDefaultRules #-}

module TestDef where

import Data.Text (Text)
import Data.ByteString (ByteString)

import Diagrams.Prelude
import Diagrams.Backend.SVG

default (Diagram SVG R2, Int, Double)

data DisplayResult = DisplayResult
     { drValue     :: Text        -- | the response sent to the client in JSON
     , drType      :: Text        -- | the type of the result for the client, 
     , drResources :: [Resource]  -- | these files are made available from the web server
     } deriving (Show, Eq)

data Resource = Resource
     { resFile        :: Text
     , resContentType :: Text
     , resData        :: ByteString
     } deriving (Show, Eq)

class Display a where
    display :: a -> DisplayResult

instance Display (Diagram SVG R2) where
  display _ = DisplayResult "this is an SVG diagram" "svg" []

-- now try:
-- > display (circle 1)

default rules? (annotation)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{-# LANGUAGE ExtendedDefaultRules, NoMonomorphismRestriction #-}

module Main where

import Diagrams.Prelude
import Diagrams.Backend.SVG

import TestDef

-- this does not work:
-- x = display (circle 1)

-- this does:
x = display (circle 1 :: Diagram SVG R2)

default rules? (annotation)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{-# LANGUAGE OverloadedStrings, FlexibleInstances, ExtendedDefaultRules #-}

module TestDef where

import Data.Text (Text)
import Data.ByteString (ByteString)

import Diagrams.Prelude
import Diagrams.Backend.SVG

default (Diagram SVG R2, Int, Double)

data DisplayResult = DisplayResult
     { drValue     :: Text        -- | the response sent to the client in JSON
     , drType      :: Text        -- | the type of the result for the client, 
     , drResources :: [Resource]  -- | these files are made available from the web server
     } deriving (Show, Eq)

data Resource = Resource
     { resFile        :: Text
     , resContentType :: Text
     , resData        :: ByteString
     } deriving (Show, Eq)

class Display a where
    display :: a -> DisplayResult

instance Display (Diagram SVG R2) where
  display _ = DisplayResult "this is an SVG diagram" "svg" []

-- now try:
-- > display (circle 1)
-- circle 1 is polymorphic in the backend and vector space, but there's only an instance for Diagram SVG R2