ocaml-programming

Simple OCaml programs
git clone git://git.laack.co/ocaml-programming.git
Log | Files | Refs | README

factorial.ipynb (1327B)


      1 {
      2  "cells": [
      3   {
      4    "cell_type": "code",
      5    "execution_count": 32,
      6    "id": "90212f01-2e8f-4533-b643-38c453ca87ba",
      7    "metadata": {},
      8    "outputs": [
      9     {
     10      "data": {
     11       "text/plain": [
     12        "val factorial : int -> int = <fun>\n"
     13       ]
     14      },
     15      "execution_count": 32,
     16      "metadata": {},
     17      "output_type": "execute_result"
     18     }
     19    ],
     20    "source": [
     21     "let rec factorial x = if x <= 1 then \n",
     22     "    if x < 0 then raise (Failure \"Factorial undefined for negative integers\") else 1 \n",
     23     "    else (factorial (x - 1)) * x;;"
     24    ]
     25   },
     26   {
     27    "cell_type": "code",
     28    "execution_count": 35,
     29    "id": "9e7b075f-f95f-4a85-95df-753c9161ccbb",
     30    "metadata": {},
     31    "outputs": [
     32     {
     33      "data": {
     34       "text/plain": [
     35        "- : int = 1\n"
     36       ]
     37      },
     38      "execution_count": 35,
     39      "metadata": {},
     40      "output_type": "execute_result"
     41     }
     42    ],
     43    "source": [
     44     "factorial (0)"
     45    ]
     46   }
     47  ],
     48  "metadata": {
     49   "kernelspec": {
     50    "display_name": "OCaml default",
     51    "language": "OCaml",
     52    "name": "ocaml-jupyter"
     53   },
     54   "language_info": {
     55    "codemirror_mode": "text/x-ocaml",
     56    "file_extension": ".ml",
     57    "mimetype": "text/x-ocaml",
     58    "name": "OCaml",
     59    "nbconverter_exporter": null,
     60    "pygments_lexer": "OCaml",
     61    "version": "4.14.2"
     62   }
     63  },
     64  "nbformat": 4,
     65  "nbformat_minor": 5
     66 }