Skip to content

Auto-force not working properly in with blocks #3461

@nmccarty

Description

@nmccarty

Using a nested with block to inspect the next step of a lazy recursive view, such as String's AsList, does not currently compile without manually forcing the value

Steps to Reproduce

Consider the following function that inspects two characters from a string at a time

doubleLetter : String -> Bool
doubleLetter str with (asList str)
  doubleLetter "" | [] = False
  doubleLetter (strCons c str) | (c :: x) with (x)
    doubleLetter (strCons c "") | (c :: x) | [] = False
    doubleLetter (strCons c (strCons d str)) | (c :: x) | (d :: y) = 
      if c == d
        then True
        else doubleLetter (strCons d str) | x

Expected Behavior

This function should either compile and work, or at least fail with a less confusing error message.

Observed Behavior

This function fails to compile, unless you replace the (x) in the inner with block with (force x), with the following error message:

 -- src/Years/Y2015/Day5.md line 72 col 14:
     While processing right hand side of with block in with block in doubleLetter. d is not accessible in
     this context.
     
     Years.Y2015.Day5:72:15--72:16
      68 |   doubleLetter "" | [] = False
      69 |   doubleLetter (strCons c str) | (c :: x) with (x)
      70 |     doubleLetter (strCons c "") | (c :: x) | [] = False
      71 |     doubleLetter (strCons c (strCons d str)) | (c :: x) | (d :: y) = 
      72 |       if c == d

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions