Skip to content

Use Number instead of Int for read #25

Closed

Description

@matthewleon

I've made a branch here to show this in a test: https://github.com/matthewleon/purescript-node-buffer/tree/uint32-test

Relevant code:

testUInt32 :: Test
testUInt32 = do
  buf <- fromArray [-1, -1, -1, -1]
  readVal <- read UInt32LE 0 buf
  logShow readVal -- 4294967295
  logShow $ readVal - 1 -- -2
  -- chaos reigns: try to uncomment the line below
  --logShow $ readVal == 4294967295

Purescript Ints really don't play nice with these operations. They probably require something like https://github.com/zaquest/purescript-uint

Activity

  1. hdgarrood commented on May 3, 2018

    @hdgarrood
    Member

    Yes, we should have these functions use a UInt type. I'd rather it be in contrib if we're going to depend on it in this library, though.

  2. matthewleon commented on May 3, 2018

    @matthewleon
    ContributorAuthor

    Makes sense. I'd be happy to see it make its way into contrib.

  3. hdgarrood commented on Dec 30, 2018

    @hdgarrood
    Member

    Come to think of it, we really ought to be using Number as the return type of read, since you can read a Double{BE,LE} or a Float{BE,LE} out of a Buffer, and clearly any integer type is unsuitable for that. Using Number as the return type addresses the UInt32 issue too. Since these libraries are meant to be low-level bindings, I think the loss of convenience is acceptable.

  4. changed the title [-]UInt32 operations: chaos reigns[/-] [+]Use Number instead of Int for `read`[/+] on Jan 13, 2019
  5. added a commit that references this issue on Mar 10, 2019
    60692d6
  6. added a commit that references this issue on Jun 30, 2019
    dac7d47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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