Giter Site home page Giter Site logo

examples's People

Contributors

anton-4 avatar cmuhire avatar dotslashbit avatar doubledup avatar fdbeirao avatar frisoft avatar isaacvando avatar kilianvounckx avatar lukewilliamboswell avatar mulias avatar ostcar avatar rtfeldman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

examples's Issues

fix pattern matching test failure

This fails with the latest roc nightly, not sure why though

โฏ ./roc_nightly/roc test ./examples/PatternMatching/PatternMatching.roc
โ”€โ”€ EXPECT FAILED โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ ./examples/PatternMatching/PatternMatching.roc โ”€

This expectation failed:

55โ”‚>  # Pattern match on a list with these exact elements: Foo, Bar, and then Baz
56โ”‚>  expect
57โ”‚>      patternMatch = \input ->
58โ”‚>          when input is
59โ”‚>              [Foo, Bar, Baz] -> Bingo
60โ”‚>              _ -> Other
61โ”‚>
62โ”‚>      (patternMatch [Foo, Bar, Baz] == Bingo)
63โ”‚>      && (patternMatch [Foo, Bar] != Bingo)
64โ”‚>      && (patternMatch [Foo, Bar, Baz, Barry] != Bingo)



1 failed and 6 passed in 197 ms.

PatternMatching

Line 65 under the TODO works, so it can be re-enabled, #25 was merged:

# TODO: reenable line below when roc-lang/examples/issues/25 is fixed
# && (patternMatch [Foo, Bar, Baz, Barry] != Bingo)           

example suggestion: string interpolation

for example, roc code that prints a string like this: "this is a number: (Num.toStr someNumber)"

Also mention these constraints:

  • it has to be one line
  • no interpolations inside other interpolations

Example suggestion: import file as str

imports [
    "some-file" as someStr : Str,
    "some-file" as someBytes : List U8,
]

Because I want examples to be what users are looking to achieve and nothing more I think "importing as Str" and "importing as List U8" should be two different examples. But they should link to each other, for example: "Importing a list of bytes may be bettere suited for your case. Read about it here"

fix json-basic example

This no longer works with the latest roc nightly, I think the json package json: "https://github.com/lukewilliamboswell/roc-package-explorations/releases/download/0.0.1/cdKMia6cwdRG6Gb0SfXP8cgGF7yTz-i959FV6ZfuS0E.tar.br" needs to be updated.

> ./roc_nightly/roc run ./examples/json-basic/main.roc
Downloading https://github.com/roc-lang/basic-cli/releases/download/0.3.2/tE4xS_zLdmmxmHwHih9kHWQ7fsXtJr7W7h3425-eZFk.tar.br
    into /home/runner/.cache/roc/packages

Downloading https://github.com/lukewilliamboswell/roc-package-explorations/releases/download/0.0.1/cdKMia6cwdRG6Gb0SfXP8cgGF7yTz-i959FV6ZfuS0E.tar.br
    into /home/runner/.cache/roc/packages
 โ”€โ”€ INCOMPLETE ABILITY IMPLEMENTATION โ”€ ...SfXP8cgGF7yTz-i959FV6ZfuS0E/Core.roc โ”€

This type does not fully implement the EncoderFormatting ability:

41โ”‚>           EncoderFormatting {
42โ”‚>               u8: encodeU8,
43โ”‚>               u16: encodeU16,
44โ”‚>               u32: encodeU32,
45โ”‚>               u64: encodeU64,
46โ”‚>               u128: encodeU128,
47โ”‚>               i8: encodeI8,
48โ”‚>               i16: encodeI16,
49โ”‚>               i32: encodeI32,
50โ”‚>               i64: encodeI64,
51โ”‚>               i128: encodeI128,
52โ”‚>               f32: encodeF32,
53โ”‚>               f64: encodeF64,
54โ”‚>               dec: encodeDec,
55โ”‚>               bool: encodeBool,
56โ”‚>               string: encodeString,
57โ”‚>               list: encodeList,
58โ”‚>               record: encodeRecord,
59โ”‚>               tag: encodeTag,
60โ”‚>           },

The following necessary members are missing implementations:

    tuple


โ”€โ”€ INCOMPLETE ABILITY IMPLEMENTATION โ”€ ...SfXP8cgGF7yTz-i959FV6ZfuS0E/Core.roc โ”€

This type does not fully implement the DecoderFormatting ability:

61โ”‚>           DecoderFormatting {
62โ”‚>               u8: decodeU8,
63โ”‚>               u16: decodeU16,
64โ”‚>               u32: decodeU32,
65โ”‚>               u64: decodeU64,
66โ”‚>               u128: decodeU128,
67โ”‚>               i8: decodeI8,
68โ”‚>               i16: decodeI16,
69โ”‚>               i32: decodeI32,
70โ”‚>               i64: decodeI64,
71โ”‚>               i128: decodeI128,
72โ”‚>               f32: decodeF32,
73โ”‚>               f64: decodeF64,
74โ”‚>               dec: decodeDec,
75โ”‚>               bool: decodeBool,
76โ”‚>               string: decodeString,
77โ”‚>               list: decodeList,
78โ”‚>               record: decodeRecord,
79โ”‚>           },

The following necessary members are missing implementations:

    tuple

โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€๏ฟฝ๏ฟฝ๏ฟฝโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

2 errors and 0 warnings found in 3057 ms.

Example suggestion: error handling

Many people will be unfamiliar with Roc error handling so I think we need a good example for it, some suggestions:

  • handling a single Result
  • handling a single Task
  • chaining Results with a pipeline
  • chaining Tasks with a pipeline
  • how to mix Task and Result

ld: warning when running example

% roc test examples/PatternMatching/PatternMatching.roc 
ld: warning: -undefined dynamic_lookup may not work with chained fixups

0 failed and 7 passed in 572 ms.

example suggestion: avoiding `{} <-` `|> await` boilerplate

We should make an example for this once we figure it out ourselves :p

Example of a problematic case:

{} <- log "Extracting current rust version from rust-toolchain.toml..." |> await
{ stable: currentStable, nightly: currentNightly } <- getCurrentVersionsFromToml |> await
{} <- log "Found versions:\n\t- stable: \(versionToStr currentStable)\n\t- nightly with date: \(dateToStr currentNightly)" |> await
# TODO Task.map to avoid repeated `{} <-`?
{} <- log "Searching for nightly matching stable-\(newRustVersion)..." |> await

newNightly <-
    findMatchingNigthly (versionFromStr newRustVersion) currentNightly
    |> await

{} <- log "New nightly: nightly-\(dateToStr newNightly)" |> await

TODO can we avoid boiler plate of `{} <-` and `await` here?
{} <-
    Path.fromStr "rust-toolchain.toml"
    |> updateToml newRustVersion
    |> await

{} <-
    Path.fromStr "examples/platform-switching/rust-platform/rust-toolchain.toml"
    |> updateToml newRustVersion
    |> await

{} <-
    Path.fromStr "Earthfile"
    |> updateEarthFile newRustVersion
    |> await

remove readargs from Arithmetic example

In line with the goal "The code snippet of the example should concisely provide the code that the user is looking for.", readargs should not be demonstrated in the Arithmetic example. We should just use fixed values instead of cli args.

We should have another example to demonstrate command line args: #39

fix examples build script (main.roc) segmentation fault

Run ./roc_nightly/roc run main.roc -- examples build
๐Ÿ”จ Rebuilding platform...
Processing 47 input files...
/home/runner/work/examples/examples/examples/CommandLineArgs/README.md -> /home/runner/work/examples/examples/build/CommandLineArgs/README.html
/home/runner/work/examples/examples/examples/TowersOfHanoi/README.md -> /home/runner/work/examples/examples/build/TowersOfHanoi/README.html
/home/runner/work/examples/examples/examples/GraphTraversal/README.md -> /home/runner/work/examples/examples/build/GraphTraversal/README.html
/home/runner/work/examples/examples/examples/PatternMatching/README.md -> /home/runner/work/examples/examples/build/PatternMatching/README.html
/home/runner/work/examples/examples/examples/Arithmetic/README.md -> /home/runner/work/examples/examples/build/Arithmetic/README.html
/home/runner/work/examples/examples/examples/HelloWorld/README.md -> /home/runner/work/examples/examples/build/HelloWorld/README.html
/home/runner/work/examples/examples/examples/RandomNumbers/README.md -> /home/runner/work/examples/examples/build/RandomNumbers/README.html
/home/runner/work/examples/examples/examples/TaskUsage/README.md -> /home/runner/work/examples/examples/build/TaskUsage/README.html
/home/runner/work/examples/examples/examples/index.md -> /home/runner/work/examples/examples/build/index.html
/home/runner/work/examples/examples/examples/LeastSquares/README.md -> /home/runner/work/examples/examples/build/LeastSquares/README.html
/home/runner/work/examples/examples/examples/Tuples/README.md -> /home/runner/work/examples/examples/build/Tuples/README.html
/home/runner/work/examples/examples/examples/IngestFiles/README.md -> /home/runner/work/examples/examples/build/IngestFiles/README.html
/home/runner/work/examples/examples/examples/Parser/README.md -> /home/runner/work/examples/examples/build/Parser/README.html
/home/runner/work/examples/examples/examples/FizzBuzz/README.md -> /home/runner/work/examples/examples/build/FizzBuzz/README.html
/home/runner/work/examples/examples/examples/Json/README.md -> /home/runner/work/examples/examples/build/Json/README.html
Processed 47 files with 15 successes and 0 errors
/home/runner/work/_temp/ea8097f9-5ff1-4662-9f07-4ff810955e2d.sh: line 1:  2975 Segmentation fault      (core dumped) ./roc_nightly/roc run main.roc -- examples build

Example Suggestion: Safe Arithmetic

Just going through the examples, thank you so much for the effort you are making here.

I am reading through the Arithmetic example and I think there's the obvious edge case about dividing by zero.

According to roc's current div documentation:

Division by zero is undefined in mathematics. As such, you should make sure never to pass zero as the denomaintor to this function! Calling div on a Dec denominator of zero will cause a panic.

Possible solutions:

  1. Adjust the example text to state that if the second argument is 0, we can skip the integer quotient operation;

  2. Adjust the example text to state that zero is not a valid input for the second argument, and add an explicit check on the readArgs function for this case

  3. Adjust the example text to state that an input of 0 on the second argument is allowed to crash with a Floating point exception

My preference would be between solution 1 or 2, or a smarter one :)

Let me know your thoughts and once again, thank you for this amazing effort!

Typo in PatternMatch example

Tag should say EndswithFoo

# Pattern match on a list that ends with a Foo tag
expect 
    patternMatch = \input ->
        when input is 
            [.., Foo] -> StartsWithFoo
            _ -> Other
    
    patternMatch [Baz, Bar, Foo] == StartsWithFoo &&
    patternMatch [Foo, Bar, Baz] != StartsWithFoo 

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.