Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider data-default for PostMessage, PostCalls, etc. #32

Open
markandrus opened this issue Apr 11, 2015 · 1 comment
Open

Consider data-default for PostMessage, PostCalls, etc. #32

markandrus opened this issue Apr 11, 2015 · 1 comment

Comments

@markandrus
Copy link
Owner

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.
@markandrus
Copy link
Owner Author

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant