-
Notifications
You must be signed in to change notification settings - Fork 48
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
Support for algebraic sum types #4
Comments
Thanks! Yes, As an added complication, |
Ok great I'll raise the issue there then. Thanks. |
Is this still an issue? |
On the other hand, |
First, let me say great work. I've really enjoyed working with servant-elm so far.
The only trouble I've run into so far with servant-elm occurs when the api for which I'm generating elm code involves algebraic sum types in some way.
E.g. Let's say my api looks like this:
type NameCompletionAPI = "nameCompletion" :> ReqBody '[JSON] NameCompletionRequest :> Get '[JSON] [Name]
And suppose the NameCompletionRequest type looks like this:
data NameCompletionRequest = NameCompletionRequest { nameSubstring :: Text , fromNationality :: Nationality , position :: Position } deriving (Generic)
and Position is a simple algebraic sum type:
data Position = Beginning | Middle | End deriving (Eq, Generic)
(Suppose too
Nationality
is just a new type wrapper aroundText
, and that we've defined all theToJSON
,FromJSON
, andElmType
orToElmType
instances for these data types.)Then on the main branch, when I go to generate this code, I'll get something like:
*** Exception: toElmTypeWithSources: Sum (Constructor "Beginning" Unit) (Sum (Constructor "Middle" Unit) (Constructor "End" Unit))
And on the devel branch, I'll get something like:
*** Exception: src/Elm/Encoder.hs:(13,1)-(58,28): Non-exhaustive patterns in function render
I was wondering if support for algebraic sum types was in the cards any time soon.
I guess this may be fundamentally more of an issue with elm-export. Let me know if it's best brought up somewhere else.
The text was updated successfully, but these errors were encountered: