Skip to content

Guards in function definition cannot work #205

@emqplus

Description

@emqplus

Define function f in Main module:

module Main where

import Prelude

main :: IO ()
main = print $ f 0

f :: Integer -> String
f n | n > 0 = "Positive Integer"
    | n < 0 = "Negative Integer"
    | otherwise = "Zero"

Compile the module:

Error found:
in module Main
at src/Main.hm:8:1 - 8:23 (line 8, column 1 - line 8, column 23)

  A case expression could not be determined to cover all inputs.
  The following additional cases are required to cover all inputs:

    _

  Alternatively, add a Partial constraint to the type of the enclosing value.

while applying a function $__unused
  of type Partial => t0 -> t0
  to argument case n of
                n | (greaterThan n) 0 -> "Positive Integer"
                  | (lessThan n) 0 -> "Negative Integer"
                  | otherwise -> "Zero"
while checking that expression $__unused (case n of
                                            n | (...) 0 -> "Positive Integer"
                                              | (...) 0 -> "Negative Integer"
                                              | otherwise -> "Zero"
                                         )
  has type List Char
in value declaration f

where t0 is an unknown type

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions