Giter Site home page Giter Site logo

munksgaard / sml Goto Github PK

View Code? Open in Web Editor NEW

This project forked from exercism/sml

0.0 2.0 0.0 333 KB

Exercism exercises in Standard ML.

Home Page: https://exercism.org/tracks/sml

License: MIT License

Standard ML 93.99% Shell 0.61% Makefile 0.71% Python 4.69%

sml's Introduction

Exercism Standard ML Track

[Configlet Status] [Exercise Test Status]

Exercism exercises in Standard ML.

Contributing Guide

Any type of contribution is more than welcome!

The first step is to get familiar with this guideline.

Setup

Even though there are multiple Standard ML implementations, we'll stick to PolyML.

Please read INSTALLATION.md for more info.

Exercise structure

Every exercise must have at least these files:

  • example.sml: Example solution
  • {{ slug }}.sml: Stub file with the same functions as example.sml
  • README.md: Exercise description
  • HINTS.md: (Optional)
  • test.sml: Test suite
  • testlib.sml Test helper

testlib.sml

This helper has this structures:

structure Expect:
  sig
    val anyError: (unit -> 'a) -> expectation
    val equalTo: ''a -> ''a -> expectation
    val error: exn -> (unit -> 'a) -> expectation
    datatype expectation = Fail of string * string | Pass
    val falsy: bool -> expectation
    val nearTo: real -> real -> expectation
    val truthy: bool -> expectation
  end
structure Test:
  sig
    val run: testnode -> 'a
    datatype testnode =
        Test of string * (unit -> Expect.expectation)
      | TestGroup of string * testnode list
  end
val describe = fn: string -> Test.testnode list -> Test.testnode
val test = fn: string -> (unit -> Expect.expectation) -> Test.testnode

Usage example:

use "foo.sml";
use "testlib.sml";

infixr |>
fun x |> f = f x

val testsuite =
  describe "Examples" [
    test "foo"
      (fn _ => foo ("foo") |> Expect.equalTo "foo-foo"),
    
    test "bar"
      (fn _ => bar () |> Expect.truthy),
    
    test "something that baz does"
      (fn _ => baz (123) |> Expect.nearTo 123.10),
    
    test "an exception from 'qux'"
      (fn _ => (fn _ => qux (0, 0))) |> Expect.error QuxError),
  ]

val _ = Test.run testsuite

Adding an exercise

The easiest way to start is by running the generator:

bin/generate {{ slug }}

It will create the exercise directory, test and stub files.

Generator

usage: generate [-h] [--force] [--test-only] [--stub-only] [--example-only]
                exercises [exercises ...]

positional arguments:
  exercises

optional arguments:
  -h, --help      show this help message and exit
  --force         Type inference will be disabled and "string" will be
                  assumed. Test cases will need to be modified to match the
                  right data type.
  --test-only     Generate only "test.sml"
  --stub-only     Generate only "<exercise>.sml"
  --example-only  Generate only "example.sml"

Note:

  • You need Python 3.5+.
  • It may fail with some exercises. Reasons:
    • canonical-data.json does not exist
    • type mismatch (in these situation you can use --force option)

In those cases you will have to create the files manually. testlib.sml can be copied from lib/testlib.sml. When in doubt, feel free to open an issue.

In order to generate README.md you will need an up to date copy of problem-specifications. This should be located at the same level as your sml clone. Then you can execute:

bin/fetch-configlet
bin/configlet generate . -o {{ slug }}

Testing

For a single exercise:

If you are at the top level:

make test-{{ slug }}

if you are in exercises/{{slug}}

make -C https://github.com/exercism/v3/blob/main/ test-{{ slug }}

If you want to run all the tests:

make test

Pull request

Do not forget to add your exercise to config.json. Please read this.

sml's People

Contributors

erikschierboom avatar snahor avatar sshine avatar kytrinyx avatar mcmillhj-wta avatar exercism-bot avatar ihid avatar joshmhanson avatar steedalion avatar sjwarner-bp avatar k4rtik avatar cyborgsphinx avatar sleeplessbyte avatar dkinzer avatar wiredancer avatar catb0t avatar cmccandless avatar jackhughesweb avatar joeltaylor avatar rainij avatar sjwarner avatar dependabot[bot] avatar ee7 avatar nywilken avatar

Watchers

James Cloos avatar  avatar

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.