Git Product home page Git Product logo

Comments (2)

evancz avatar evancz commented on July 19, 2024

I want to keep native code as a last resort for expressiveness, and I think this can be expressed without massive issues in pure Elm.

For example, List.foldl is implemented as a loop under the hood, so it seems that defining your stuff in terms of that would be no problem. To do foldr maybe you want to use List.reverse but we are talking about non-crazy costs here. Does that route seem plausible? If not, why not?

from package.elm-lang.org.

jonathanhefner avatar jonathanhefner commented on July 19, 2024

Although Range.foldl could be expressed in terms of List.foldl, it would require allocating an intermediary list. If you want to work with a large range, for example range 0 50000 |> foldl (+) 0, that may be impractical.

But further, I had envisioned using this as a simple and safe looping mechanism for counted loops. As an example, several List API functions which currently require native code (for safety) could be expressed in terms of Range.foldl:

drop : Int -> List a -> List a
drop n xs =
  let drop1 _ xs' =
        case xs' of
          _::rest -> rest
          _ -> []
  in
      0 `to` n |> Range.foldl drop1 xs

repeat : Int -> a -> List a
repeat n x =
  let cons1 _ xs = x :: xs
  in
      0 `to` n |> Range.foldl cons1 []

I agree that we should be eliminating native code wherever possible (for all the reasons stated in elm-lang/core#130). In this case, I felt Range.foldl would actually help move towards that goal.

from package.elm-lang.org.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.