Skip to content

Whole Story Recursion Does Not Work in Elm 0.19 #4

@rue

Description

@rue
module SumTypes.WholeStorySolution exposing (..)

type Silly a b
  = AsA a
  | AsB b
  | AlsoAsA a

  | AsInt Int

  | AsFloatString Float String
  | AsBoth a b
  | AsIntB Int b

  | AsMaybe (Maybe b)
  | AsMaybeInt (Maybe Int)
  | DeeplySilly (Silly a a) (Silly Int b)
  | NoArg

bVals : Silly a b -> Maybe b
bVals silly =
  case silly of 
    AsB b -> Just b
    AsBoth _ b -> Just b
    AsIntB _ b -> Just b
    AsMaybe (Just b) -> Just b  -- could just be AsMaybe maybe -> maybe
    DeeplySilly _ nested -> bVals nested           -- <--- Problem here
_ -> Nothing

Produces an error on 0.19:

Detected errors in 1 module.                                         
-- TYPE MISMATCH --------------------------------------------- src/SumTypes/WholeStorySolution.elm

The 1st argument to `bVals` is not what I expect:

171|             bVals nested
                       ^^^^^^^^^^
This `nested` value is a:

    Silly Int b

But `bVals` needs the 1st argument to be:

    Silly a b

Hint: Your type annotation uses type variable `a` which means ANY type of value
can flow through, but your code is saying it specifically wants a `Int` value.
Maybe change your type annotation to be more specific? Maybe change the code to
be more general?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions