Iterate for NonEmptyList behaves strange
Masynchin opened this issue · 4 comments
Masynchin commented
Code
import Prelude
import Data.List.Types (NonEmptyList)
import Data.List.Lazy.NonEmpty (iterate)
type Item = { key :: Boolean }
iterateItems :: NonEmptyList Item
iterateItems = iterate stable { key: true }
stable :: forall a. a -> a
stable x = xCurrent Behavior
Compiler raises this error about iterateItems:
Could not match type
NonEmptyList
with type
NonEmptyList
while trying to match type NonEmptyList t0
with type NonEmptyList
{ key :: Boolean
}
while checking that expression (iterate stable) { key: true
}
has type NonEmptyList
{ key :: Boolean
}
in value declaration iterateItems
where t0 is an unknown type
PureScript(TypesDoNotUnify)
No quick fixes available
Expected Behavior
Compiler not raises any errors.
Libs
- PureScript: 0.15.2
- PureScript-Lists: 7.0.0
Masynchin commented
Same with repeat:
infiniteNums :: NonEmptyList Int
infiniteNums = repeat 1For this code compiler raises:
Could not match type
NonEmptyList
with type
NonEmptyList
while trying to match type NonEmptyList t0
with type NonEmptyList Int
while checking that expression repeat 1
has type NonEmptyList Int
in value declaration infiniteNums
garyb commented
You've imported the non-lazy NonEmptyList type here, hence the mismatch. There's an issue in the compiler repo (and a PR has recently been opened) that should help with these cases by qualifying type names.
Masynchin commented
Thanks for explaining difference. I came to this issue trying power NEL, but since it is not Monoid, I can't do it this way. I thought I can replace it with repeat/iterate identity + take, but there is no take for this lazy NEL. You solved my issue, this is just background for issue.
Masynchin commented
I just found this function which do want I want.