From a0680bf0c362cfa12568fc6b8a3bac99efb2fde9 Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Freeman <the@jeffreyfreeman.me> Date: Sun, 5 Nov 2023 02:32:18 -0500 Subject: [PATCH] Fixed the lack of dependencies in ihaskell --- Dockerfile | 18 +- .../haskell-checkpoint.ipynb | 456 +++++++++++++++++- examples/haskell.ipynb | 197 +++++++- 3 files changed, 643 insertions(+), 28 deletions(-) diff --git a/Dockerfile b/Dockerfile index b17bb2a..ba4342d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -300,21 +300,8 @@ RUN curl -Lo coursier https://git.io/coursier-cli \ ## Install IHaskell ## - -#RUN curl -sSL https://get.haskellstack.org/ | sh && \ -# mkdir -p /etc/stack && \ -# mkdir -p /root/.stack/global-project - -#COPY .docker/stack.config.yaml /etc/stack/config.yaml -#COPY .docker/global-project.stack.yaml /root/.stack/global-project/stack.yaml - ENV PATH ${PATH}:/opt/bin:/opt/ghc/bin -#RUN mkdir -p /usr/local/share/jupyter/kernels && \ -# mkdir -p /opt/bin && \ -# stack setup && \ -# rm -f /root/.stack/programs/x86_64-linux/ghc*.tar.xz - RUN mkdir -p /opt/bin && \ apt-get install -y --no-install-recommends \ python3-pip \ @@ -341,12 +328,13 @@ RUN cd IHaskell && \ mv /root/.local/bin/* /opt/bin/ &&\ ihaskell install --stack +RUN stack install hashable && \ + stack install unordered-containers + #RUN mkdir -p /root/.local/share/jupyter/runtime && \ # mkdir -p /opt/ghc && \ # ln -s `stack path --compiler-bin` /opt/ghc/bin -#RUN stack exec ihaskell -- install --stack --prefix=/usr/local - # ↓ 削除系ã¯ã¯ã¾ã¨ã‚ã¦ã“ã“ã§ã‚„ã‚‹ RUN mamba clean --all \ && apt-get autoremove \ diff --git a/examples/.ipynb_checkpoints/haskell-checkpoint.ipynb b/examples/.ipynb_checkpoints/haskell-checkpoint.ipynb index 19c9e18..90cc915 100644 --- a/examples/.ipynb_checkpoints/haskell-checkpoint.ipynb +++ b/examples/.ipynb_checkpoints/haskell-checkpoint.ipynb @@ -2,10 +2,266 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "1bf0ed67-d8ce-4fe7-93d7-58a73a51c80d", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "<style>/* Styles used for the Hoogle display in the pager */\n", + ".hoogle-doc {\n", + "display: block;\n", + "padding-bottom: 1.3em;\n", + "padding-left: 0.4em;\n", + "}\n", + ".hoogle-code {\n", + "display: block;\n", + "font-family: monospace;\n", + "white-space: pre;\n", + "}\n", + ".hoogle-text {\n", + "display: block;\n", + "}\n", + ".hoogle-name {\n", + "color: green;\n", + "font-weight: bold;\n", + "}\n", + ".hoogle-head {\n", + "font-weight: bold;\n", + "}\n", + ".hoogle-sub {\n", + "display: block;\n", + "margin-left: 0.4em;\n", + "}\n", + ".hoogle-package {\n", + "font-weight: bold;\n", + "font-style: italic;\n", + "}\n", + ".hoogle-module {\n", + "font-weight: bold;\n", + "}\n", + ".hoogle-class {\n", + "font-weight: bold;\n", + "}\n", + "\n", + ".get-type {\n", + "color: green;\n", + "font-weight: bold;\n", + "font-family: monospace;\n", + "display: block;\n", + "white-space: pre-wrap;\n", + "}\n", + ".show-type {\n", + "color: green;\n", + "font-weight: bold;\n", + "font-family: monospace;\n", + "margin-left: 1em;\n", + "}\n", + ".mono {\n", + "font-family: monospace;\n", + "display: block;\n", + "}\n", + ".err-msg {\n", + "color: red;\n", + "font-style: italic;\n", + "font-family: monospace;\n", + "white-space: pre;\n", + "display: block;\n", + "}\n", + "#unshowable {\n", + "color: red;\n", + "font-weight: bold;\n", + "}\n", + ".err-msg.in.collapse {\n", + "padding-top: 0.7em;\n", + "}\n", + "\n", + ".highlight-code {\n", + "white-space: pre;\n", + "font-family: monospace;\n", + "}\n", + "\n", + ".suggestion-warning { \n", + "font-weight: bold;\n", + "color: rgb(200, 130, 0);\n", + "}\n", + ".suggestion-error { \n", + "font-weight: bold;\n", + "color: red;\n", + "}\n", + ".suggestion-name {\n", + "font-weight: bold;\n", + "}\n", + "\n", + "</style><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(Maybe l) -> (Maybe r) -> m -> m</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">Maybe l -> (Maybe r) -> m -> m</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(Maybe r) -> m -> m</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">Maybe r -> m -> m</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(Maybe l) -> (Maybe r) -> m -> m</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">Maybe l -> (Maybe r) -> m -> m</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(Maybe r) -> m -> m</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">Maybe r -> m -> m</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Use Just</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">fromMaybe\n", + " False\n", + " ((isJust . HashMap.lookup l) <$> (HashMap.lookup r (rightMap m)))</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">Just True\n", + " ==\n", + " ((isJust . HashMap.lookup l) <$> (HashMap.lookup r (rightMap m)))</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Use maybe</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">fromMaybe\n", + " False\n", + " ((isJust . HashMap.lookup l) <$> (HashMap.lookup r (rightMap m)))</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">maybe\n", + " False (isJust . HashMap.lookup l) (HashMap.lookup r (rightMap m))</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(isJust . HashMap.lookup l) <$> (HashMap.lookup r (rightMap m))</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">isJust . HashMap.lookup l <$> (HashMap.lookup r (rightMap m))</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(isJust . HashMap.lookup l) <$> (HashMap.lookup r (rightMap m))</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">(isJust . HashMap.lookup l) <$> HashMap.lookup r (rightMap m)</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(Right)</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">Right</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(Right) <$> (HashMap.lookup l (leftMap m))</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">(Right) <$> HashMap.lookup l (leftMap m)</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(Left)</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">Left</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(Left) <$> (HashMap.lookup r (rightMap m))</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">(Left) <$> HashMap.lookup r (rightMap m)</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(HashMap.empty)</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">HashMap.empty</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(HashMap.empty)</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">HashMap.empty</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Eta reduce</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">adjustFunc r old\n", + " = HashMap.update\n", + " (\\ old -> if old <= 1 then Nothing else Just (old - 1)) r old</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">adjustFunc\n", + " = HashMap.update\n", + " (\\ old -> if old <= 1 then Nothing else Just (old - 1))</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(lm)</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">lm</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(rm)</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">rm</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(insertFunc)</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">insertFunc</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(insertFunc)</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">insertFunc</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Eta reduce</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">insertFunc new old = insertFuncArray (HashMap.toList new) old</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">insertFunc new = insertFuncArray (HashMap.toList new)</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Avoid lambda</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">\\ n o -> n + o</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">(+)</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(asListOuterLeft (HashMap.toList lm))\n", + " ++ (asListOrphanRight (HashMap.toList rm))</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">asListOuterLeft (HashMap.toList lm)\n", + " ++ (asListOrphanRight (HashMap.toList rm))</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(asListOuterLeft (HashMap.toList lm))\n", + " ++ (asListOrphanRight (HashMap.toList rm))</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">(asListOuterLeft (HashMap.toList lm))\n", + " ++ asListOrphanRight (HashMap.toList rm)</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(asListOrphanRight ks)\n", + " ++ if (m == HashMap.empty) then [(Nothing, Just r)] else []</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">asListOrphanRight ks\n", + " ++ if (m == HashMap.empty) then [(Nothing, Just r)] else []</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Use list comprehension</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">if (m == HashMap.empty) then [(Nothing, Just r)] else []</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">([(Nothing, Just r) | m == HashMap.empty])</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">if (m == HashMap.empty) then [(Nothing, Just r)] else []</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">if m == HashMap.empty then [(Nothing, Just r)] else []</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">if (m == HashMap.empty) then\n", + " [(Just l, Nothing)]\n", + "else\n", + " assocLeft l (HashMap.toList m)</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">if m == HashMap.empty then\n", + " [(Just l, Nothing)]\n", + "else\n", + " assocLeft l (HashMap.toList m)</div></div><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(pairs l r c) ++ assocLeft l rs</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">pairs l r c ++ assocLeft l rs</div></div>" + ], + "text/plain": [ + "Line 33: Redundant bracket\n", + "Found:\n", + "(Maybe l) -> (Maybe r) -> m -> m\n", + "Why not:\n", + "Maybe l -> (Maybe r) -> m -> mLine 34: Redundant bracket\n", + "Found:\n", + "(Maybe r) -> m -> m\n", + "Why not:\n", + "Maybe r -> m -> mLine 39: Redundant bracket\n", + "Found:\n", + "(Maybe l) -> (Maybe r) -> m -> m\n", + "Why not:\n", + "Maybe l -> (Maybe r) -> m -> mLine 40: Redundant bracket\n", + "Found:\n", + "(Maybe r) -> m -> m\n", + "Why not:\n", + "Maybe r -> m -> mLine 52: Use Just\n", + "Found:\n", + "fromMaybe\n", + " False\n", + " ((isJust . HashMap.lookup l) <$> (HashMap.lookup r (rightMap m)))\n", + "Why not:\n", + "Just True\n", + " ==\n", + " ((isJust . HashMap.lookup l) <$> (HashMap.lookup r (rightMap m)))Line 52: Use maybe\n", + "Found:\n", + "fromMaybe\n", + " False\n", + " ((isJust . HashMap.lookup l) <$> (HashMap.lookup r (rightMap m)))\n", + "Why not:\n", + "maybe\n", + " False (isJust . HashMap.lookup l) (HashMap.lookup r (rightMap m))Line 52: Redundant bracket\n", + "Found:\n", + "(isJust . HashMap.lookup l) <$> (HashMap.lookup r (rightMap m))\n", + "Why not:\n", + "isJust . HashMap.lookup l <$> (HashMap.lookup r (rightMap m))Line 52: Redundant bracket\n", + "Found:\n", + "(isJust . HashMap.lookup l) <$> (HashMap.lookup r (rightMap m))\n", + "Why not:\n", + "(isJust . HashMap.lookup l) <$> HashMap.lookup r (rightMap m)Line 57: Redundant bracket\n", + "Found:\n", + "(Right)\n", + "Why not:\n", + "RightLine 57: Redundant bracket\n", + "Found:\n", + "(Right) <$> (HashMap.lookup l (leftMap m))\n", + "Why not:\n", + "(Right) <$> HashMap.lookup l (leftMap m)Line 58: Redundant bracket\n", + "Found:\n", + "(Left)\n", + "Why not:\n", + "LeftLine 58: Redundant bracket\n", + "Found:\n", + "(Left) <$> (HashMap.lookup r (rightMap m))\n", + "Why not:\n", + "(Left) <$> HashMap.lookup r (rightMap m)Line 68: Redundant bracket\n", + "Found:\n", + "(HashMap.empty)\n", + "Why not:\n", + "HashMap.emptyLine 68: Redundant bracket\n", + "Found:\n", + "(HashMap.empty)\n", + "Why not:\n", + "HashMap.emptyLine 109: Eta reduce\n", + "Found:\n", + "adjustFunc r old\n", + " = HashMap.update\n", + " (\\ old -> if old <= 1 then Nothing else Just (old - 1)) r old\n", + "Why not:\n", + "adjustFunc\n", + " = HashMap.update\n", + " (\\ old -> if old <= 1 then Nothing else Just (old - 1))Line 112: Redundant bracket\n", + "Found:\n", + "(lm)\n", + "Why not:\n", + "lmLine 141: Redundant bracket\n", + "Found:\n", + "(rm)\n", + "Why not:\n", + "rmLine 169: Redundant bracket\n", + "Found:\n", + "(insertFunc)\n", + "Why not:\n", + "insertFuncLine 170: Redundant bracket\n", + "Found:\n", + "(insertFunc)\n", + "Why not:\n", + "insertFuncLine 173: Eta reduce\n", + "Found:\n", + "insertFunc new old = insertFuncArray (HashMap.toList new) old\n", + "Why not:\n", + "insertFunc new = insertFuncArray (HashMap.toList new)Line 175: Avoid lambda\n", + "Found:\n", + "\\ n o -> n + o\n", + "Why not:\n", + "(+)Line 199: Redundant bracket\n", + "Found:\n", + "(asListOuterLeft (HashMap.toList lm))\n", + " ++ (asListOrphanRight (HashMap.toList rm))\n", + "Why not:\n", + "asListOuterLeft (HashMap.toList lm)\n", + " ++ (asListOrphanRight (HashMap.toList rm))Line 199: Redundant bracket\n", + "Found:\n", + "(asListOuterLeft (HashMap.toList lm))\n", + " ++ (asListOrphanRight (HashMap.toList rm))\n", + "Why not:\n", + "(asListOuterLeft (HashMap.toList lm))\n", + " ++ asListOrphanRight (HashMap.toList rm)Line 207: Redundant bracket\n", + "Found:\n", + "(asListOrphanRight ks)\n", + " ++ if (m == HashMap.empty) then [(Nothing, Just r)] else []\n", + "Why not:\n", + "asListOrphanRight ks\n", + " ++ if (m == HashMap.empty) then [(Nothing, Just r)] else []Line 208: Use list comprehension\n", + "Found:\n", + "if (m == HashMap.empty) then [(Nothing, Just r)] else []\n", + "Why not:\n", + "([(Nothing, Just r) | m == HashMap.empty])Line 208: Redundant bracket\n", + "Found:\n", + "if (m == HashMap.empty) then [(Nothing, Just r)] else []\n", + "Why not:\n", + "if m == HashMap.empty then [(Nothing, Just r)] else []Line 227: Redundant bracket\n", + "Found:\n", + "if (m == HashMap.empty) then\n", + " [(Just l, Nothing)]\n", + "else\n", + " assocLeft l (HashMap.toList m)\n", + "Why not:\n", + "if m == HashMap.empty then\n", + " [(Just l, Nothing)]\n", + "else\n", + " assocLeft l (HashMap.toList m)Line 232: Redundant bracket\n", + "Found:\n", + "(pairs l r c) ++ assocLeft l rs\n", + "Why not:\n", + "pairs l r c ++ assocLeft l rs" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "{-# LANGUAGE MultiParamTypeClasses #-}\n", "{-# LANGUAGE FunctionalDependencies #-}\n", @@ -246,9 +502,196 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "b2b27113-285a-4de6-bb4a-1f988ec1e62b", "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Just (Right (fromList [(\"b\",1),(\"a\",2),(\"c\",1)]))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Just (Right (fromList [(\"c\",1)]))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Just (Left (fromList [(5,2)]))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Just (Left (fromList [(5,1)]))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Just (Left (fromList [(5,1),(6,1)]))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "a = insert (Just 6) (Just \"c\") $\n", + " insert (Just 5) (Just \"c\") $\n", + " insert (Just 5) (Just \"b\") $\n", + " insert (Just 5) (Just \"a\") $\n", + " insert (Just 5) (Just \"a\") empty\n", + "\n", + "lookup (Left 5) a\n", + "lookup (Left 6) a\n", + "lookup (Right \"a\") a\n", + "lookup (Right \"b\") a\n", + "lookup (Right \"c\") a\n", + "\n", + "contains (Just 5) (Just \"c\") a" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "0d7a5935-ae5f-433b-bdf0-b15b6329992a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Nothing" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Just (Right (fromList [(\"c\",1)]))" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "b = delete (Just 5) Nothing a\n", + "\n", + "lookup (Left 5) b\n", + "lookup (Left 6) b" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a98b3909-50a3-4583-8c15-59aaf42b4d1b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Nothing" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Just (Right (fromList [(\"g\",1),(\"c\",1)]))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Just (Right (fromList [(\"g\",1),(\"c\",2)]))" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "c = insert (Just 7) (Just \"c\") $\n", + " insert (Just 7) (Just \"g\") $\n", + " insert (Just 6) (Just \"g\") $\n", + " insert (Just 7) (Just \"c\") $\n", + " insert (Just 6) (Just \"c\") empty\n", + " \n", + "lookup (Left 5) c\n", + "lookup (Left 6) c\n", + "lookup (Left 7) c" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bef39b82-e800-4390-95ed-226f32c7ca0d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Just (Right (fromList [(\"g\",1)]))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Just (Right (fromList [(\"g\",1)]))" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "d = delete Nothing (Just \"c\") c\n", + "\n", + "lookup (Left 6) d\n", + "lookup (Left 7) d" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5b14c1db-9871-4aea-a8e5-cc5f4b0dd36a", + "metadata": {}, "outputs": [], "source": [] } @@ -260,7 +703,12 @@ "name": "haskell" }, "language_info": { - "name": "" + "codemirror_mode": "ihaskell", + "file_extension": ".hs", + "mimetype": "text/x-haskell", + "name": "haskell", + "pygments_lexer": "Haskell", + "version": "9.4.7" } }, "nbformat": 4, diff --git a/examples/haskell.ipynb b/examples/haskell.ipynb index f8a392a..90cc915 100644 --- a/examples/haskell.ipynb +++ b/examples/haskell.ipynb @@ -260,14 +260,6 @@ }, "metadata": {}, "output_type": "display_data" - }, - { - "ename": "", - "evalue": "", - "output_type": "error", - "traceback": [ - "<interactive>:1:1: error:\n Could not find module ‘Data.Hashable’\n Use -v (or `:set -v` in ghci) to see a list of the files searched for." - ] } ], "source": [ @@ -510,9 +502,196 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "b2b27113-285a-4de6-bb4a-1f988ec1e62b", "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Just (Right (fromList [(\"b\",1),(\"a\",2),(\"c\",1)]))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Just (Right (fromList [(\"c\",1)]))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Just (Left (fromList [(5,2)]))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Just (Left (fromList [(5,1)]))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Just (Left (fromList [(5,1),(6,1)]))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "a = insert (Just 6) (Just \"c\") $\n", + " insert (Just 5) (Just \"c\") $\n", + " insert (Just 5) (Just \"b\") $\n", + " insert (Just 5) (Just \"a\") $\n", + " insert (Just 5) (Just \"a\") empty\n", + "\n", + "lookup (Left 5) a\n", + "lookup (Left 6) a\n", + "lookup (Right \"a\") a\n", + "lookup (Right \"b\") a\n", + "lookup (Right \"c\") a\n", + "\n", + "contains (Just 5) (Just \"c\") a" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "0d7a5935-ae5f-433b-bdf0-b15b6329992a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Nothing" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Just (Right (fromList [(\"c\",1)]))" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "b = delete (Just 5) Nothing a\n", + "\n", + "lookup (Left 5) b\n", + "lookup (Left 6) b" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a98b3909-50a3-4583-8c15-59aaf42b4d1b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Nothing" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Just (Right (fromList [(\"g\",1),(\"c\",1)]))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Just (Right (fromList [(\"g\",1),(\"c\",2)]))" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "c = insert (Just 7) (Just \"c\") $\n", + " insert (Just 7) (Just \"g\") $\n", + " insert (Just 6) (Just \"g\") $\n", + " insert (Just 7) (Just \"c\") $\n", + " insert (Just 6) (Just \"c\") empty\n", + " \n", + "lookup (Left 5) c\n", + "lookup (Left 6) c\n", + "lookup (Left 7) c" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bef39b82-e800-4390-95ed-226f32c7ca0d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Just (Right (fromList [(\"g\",1)]))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Just (Right (fromList [(\"g\",1)]))" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "d = delete Nothing (Just \"c\") c\n", + "\n", + "lookup (Left 6) d\n", + "lookup (Left 7) d" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5b14c1db-9871-4aea-a8e5-cc5f4b0dd36a", + "metadata": {}, "outputs": [], "source": [] } -- GitLab