You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code runs fine with ghc (printing Nothing):
moduleWhereGuardBugwherereadDriveShare:: [Char] ->Maybe ([Char], [Char])
readDriveShare (x:xs) | x =='/'=Just (x:a,b)
where (a,b) = (['f'],['g'])
readDriveShare _ =Nothing
main =print$ readDriveShare ('f':'i':'l':'e':[])
When compiling with frege, I get
W whereGuardBug.hs:4: guard (== x '/') may evaluate to false.
and at runtime
Exception in thread "main" frege.runtime.NoMatch: readDriveShare at line 4 no match for value frege.prelude.PreludeBase$TTuple2@70177ecd
at WhereGuardBug.readDriveShare(WhereGuardBug.java:90)
at WhereGuardBug.lambda$null$2(WhereGuardBug.java:135)
at frege.run8.Thunk.call(Thunk.java:231)
at WhereGuardBug.lambda$null$0(WhereGuardBug.java:127)
at frege.run8.Thunk.call(Thunk.java:231)
at WhereGuardBug.lambda$static$3(WhereGuardBug.java:153)
at frege.run8.Thunk.call(Thunk.java:231)
at WhereGuardBug.main(WhereGuardBug.java:162)
The text was updated successfully, but these errors were encountered:
This is yet another silly bug arising from the pattern binding in the where clause (a construct I never use, which may explain why I didn't recognize this before).
This gets translated into a something like
readDriveShare (x:xs) = case (['f'], ['g']) of (a,b) | x == '/' = Just (x:a,b)
but this wrong here, because the guard must not slip inside.
The following code runs fine with ghc (printing
Nothing
):When compiling with frege, I get
and at runtime
The text was updated successfully, but these errors were encountered: