snoyberg / mono-traversable

Type classes for mapping, folding, and traversing monomorphic containers
153 stars 63 forks source link

last of a list of text should work, but doesn't #108

Open bitemyapp opened 7 years ago

bitemyapp commented 7 years ago
Prelude> :t T.split (\c -> c == '.') "filename.pdf"
T.split (\c -> c == '.') "filename.pdf" :: [Text]
Prelude> last $ T.split (\c -> c == '.') "filename.pdf"

<interactive>:12:1:
    Couldn't match expected type ‘Element mono’
                with actual type ‘Element mono0’
    NB: ‘Element’ is a type function, and may not be injective
    The type variable ‘mono0’ is ambiguous
    When checking that ‘it’ has the inferred type
      it :: forall mono. Element mono
    Probable cause: the inferred type is ambiguous

<interactive>:12:8:
    Couldn't match expected type ‘MinLen (Succ nat0) mono’
                with actual type ‘[Text]’
    Relevant bindings include
      it :: Element mono (bound at <interactive>:12:1)
    In the second argument of ‘($)’, namely
      ‘T.split (\ c -> c == '.') "filename.pdf"’
    In the expression: last $ T.split (\ c -> c == '.') "filename.pdf"

What gives?

bitemyapp commented 7 years ago

I know it's partial, but the type error is baffling. Contrast:

Prelude> import qualified Prelude
Prelude> Prelude.last $ T.split (\c -> c == '.') "filename.pdf"
"pdf"
MaxGabriel commented 7 years ago

Just off the top of my head, is it because the Text doesn't have a guaranteed minimum length, and without that last could be partial, that's why it's not compiling?

bitemyapp commented 7 years ago

@MaxGabriel I think it's because the [] of [Text] doesn't have MinLen.

snoyberg commented 7 years ago

Try using a more recent version of mono-traversable, it should give a much clearer error message. On mobile, I can't check myself right now.

On Fri, Sep 16, 2016, 12:32 AM Chris Allen notifications@github.com wrote:

@MaxGabriel https://github.com/MaxGabriel I think it's because the [] of [Text] doesn't have MinLen.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/snoyberg/mono-traversable/issues/108#issuecomment-247461528, or mute the thread https://github.com/notifications/unsubscribe-auth/AADBB0QzRPY_WawzMBJaHamdrHgxHaqFks5qqblSgaJpZM4J-VVK .

BebeSparkelSparkel commented 1 month ago

This does appear to be fixed.