markandrus/twilio-haskell

Consider data-default for PostMessage, PostCalls, etc.

Opened this issue · 1 comments

A number of data types for POSTing to the /Message.json resource, the /Calls.json resource, etc., can and will have a number of optional parameters. Investigate using data-default for such cases.

Open question: can we easily write Default instances that do require some values? e.g.

instance Default (Text -> Text -> URI -> PostCalls) where
   def to from url = PostCalls to from url Nothing Nothing Nothing -- etc.

With careful use of OverlappingInstances, it's probably fine:

{-#LANGUAGE OverlappingInstances #-}

module Main where

import Data.Default

data Foo a b = Foo
  { optional :: Maybe a
  , required :: b }
  deriving Show

instance Default b => Default (Foo a b) where
  def = Foo Nothing def

instance Default (b -> Foo a b) where
  def = Foo Nothing

foo1 :: Foo () ()
foo1 = def

foo2 :: Foo () String
foo2 = def "foo"