Commit fd0839e5 authored by Valentin Reis's avatar Valentin Reis
Browse files

[refactor] major refactor and addition of a tutorial file.

parent f99c2b52
......@@ -39,17 +39,6 @@ hlint:
script:
- nix-shell --pure -p '(import ./.).hlint' --run bash <<< 'hlint src/ --hint=./.hlint.yaml'
black:
stage: source
tags:
- kvm
- nix
script:
- |
nix-shell --pure -p '(import ./.).pythonPackages.black' --run bash <<< '
black validation/*.py --check
'
dhall-format:
stage: source
tags:
......@@ -76,7 +65,6 @@ nix-build:
- nix
script: nix-build -A hbandit --no-build-output
check-vendored-documentation:
stage: docs
tags:
......
This diff is collapsed.
Copyright (c) 2019, UChicago Argonne, LLC. All Rights Reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# this file was tested using GNUMAKE >= 4.2.1.
# this is necessary for using multi-line strings as command arguments.
SHELL := $(shell which bash)
# this allows omitting newlines.
.ONESHELL:
# "nix-shell -p" constructs an expression that relies on <nixpkgs> for
# selecting attributes, so we override it.
# https://github.com/NixOS/nix/issues/726#issuecomment-161215255
NIX_PATH := nixpkgs=./.
.PHONY: vendor
vendor: hbandit.nix
dhall-to-cabal: default.nix
rm -rf ./dhall-to-cabal
cp -r $$(nix-build -A dhall-to-cabal-resources --no-out-link) ./dhall-to-cabal
chmod -R +rw ./dhall-to-cabal
#generating the vendored cabal file.
.PRECIOUS: hbandit.cabal
hbandit.cabal: hbandit.dhall dhall-to-cabal
@nix-shell --pure -E '
with import <nixpkgs> {};
mkShell {
buildInputs = [ haskellPackages.dhall-to-cabal ];
LOCALE_ARCHIVE="$${pkgs.glibcLocales}/lib/locale/locale-archive";
LANG="en_US.UTF-8";
}
' --run bash <<< '
dhall-to-cabal hbandit.dhall
'
.PRECIOUS: hbandit.nix
hbandit.nix: hbandit.cabal
@nix-shell --pure -p cabal2nix --run bash <<< '
cabal2nix . > hbandit.nix
'
.PHONY: ci
ci:
@nix-shell -p yq -p jq --run bash <<< '
for jobname in $$(yq -r "keys| .[]" .gitlab-ci.yml); do
if [ "$$jobname" != "stages" ]; then
gitlab-runner exec shell "$$jobname"
fi
done
'
ci-%:
@nix-shell --run bash <<< '
gitlab-runner exec shell "$*"
'
.PHONY: ghcid
ghcid: ghcid-hbandit
ghcid-hbandit: hbandit.cabal .hlint.yaml hbandit.nix
@nix-shell -E '
with import <nixpkgs> {};
with haskellPackages;
shellFor {
packages = p: [p.hbandit];
buildInputs = [ghcid cabal-install hlint];
}
' --pure --run bash <<< '
ghcid --command "cabal v2-repl hbandit " \
--restart=hbandit.cabal \
--restart=default.nix \
-l
'
ghcid-test: hbandit.cabal .hlint.yaml hbandit.nix
@nix-shell --pure --run bash <<< '
ghcid --command "cabal v2-repl test " \
--restart=hbandit.cabal \
--restart=default.nix \
-l
'
.PHONY: pre-commit
pre-commit: ormolu dhall-format shellcheck
.PHONY: shellcheck
shellcheck:
@nix-shell --pure -p fd shellcheck --run bash <<< '
for F in $$(fd -e sh); do
shellcheck -s bash $$F
done
'
.PHONY: dhall-format
dhall-format:
@nix-shell --pure -p fd haskellPackages.dhall --run bash <<< '
for F in $$(fd -e dhall); do
dhall format --inplace $$F
done
'
.PHONY: ormolu
ormolu:
@nix-shell --pure -E '
let pkgs = (import ./. {});
in pkgs.mkShell {
buildInputs = [pkgs.fd pkgs.ormolu];
shellHook =
"export LOCALE_ARCHIVE=$${pkgs.glibcLocales}/lib/locale/locale-archive \n" +
"export LANG=en_US.UTF-8";
}
' --run bash <<< '
for F in $$(fd -e hs); do
ormolu -o -XTypeApplications -o -XPatternSynonyms -m inplace $$F
done
'
.PHONY: doc
doc: src/HBandit/Tutorial.hs hbandit.cabal hbandit.nix
@nix-shell -E '
with import <nixpkgs> {};
with haskellPackages;
shellFor {
packages = p: [p.hbandit];
buildInputs = [cabal-install];
}
' --run <<< bash '
cabal v2-haddock hbandit --haddock-internal --builddir=.build
'
.PRECIOUS: src/HBandit/Tutorial.hs
src/HBandit/Tutorial.hs: literate/tutorial.md hbandit.nix src
@nix-shell --pure -E '
with import <nixpkgs> {};
with haskellPackages;
let extra = { mkDerivation, inline-r, pretty-simple, aeson, stdenv }:
mkDerivation {
pname = "extra";
version = "1.0.0";
src = "";
libraryHaskellDepends = [
aeson
inline-r
pretty-simple
];
description = "extra";
license = stdenv.lib.licenses.bsd3;
};
in
shellFor {
packages = p: [
p.hbandit
(haskellPackages.callPackage extra {})
];
buildInputs = [
inline-r
aeson
pretty-simple
panhandle
panpipe
unlit
pandoc
pkgs.which
cabal-install
R];
R_LIBS_SITE = "$${builtins.readFile r-libs-site}";
}
' --run bash <<< '
pandoc --filter $$(which panpipe) --filter $$(which panhandle) -f markdown+lhs -t markdown+lhs $< | unlit -f bird > $@
'
.PHONY:clean
clean:
rm -rf .build
rm -rf dist*
rm -f literate/main.hs
rm -f src/HBandit/Tutorial.hs
rm -f hbandit.nix
rm -f hbandit.cabal
rm -rf dhall-to-cabal
# hbandit
Multi-Armed Bandit implementations: EXP, BwCR (wip), Exp4.R
## Install
Provision using either Cabal or Nix toolchain. Both cabal file and nix packages
are provided in the repository.
## Notebooks
Provision using Nix (`nix-shell`) and run notebook
[validation/benchmark.ipynb](validation/benchmark.ipynb). Nix one-liner:
```
nix-shell "https://xgitlab.cels.anl.gov/argo/hbandit/-/archive/master/hbandit-master.tar.gz" --pure -A validation --arg useGhcide false --run 'jupyter-notebook $NOTEBOOKS/benchmark.ipynb'
```
## Doc
[haddocks](https://hbandit.readthedocs.io/en/latest/_static/haddocks/)
Safe Multi-Armed Bandit implementations: EXP3, BwCR (wip), Exp4.R
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
-- |
-- Module : main
-- Copyright : (c) 2019, UChicago Argonne, LLC.
-- License : BSD3
-- Maintainer : fre@freux.fr
module Shared
(
)
where
import Data.List.NonEmpty
import Data.MessagePack
import FFI.TypeUncurry.Msgpack
import Foreign.C
import HBandit.Class
import HBandit.Exp3
import Protolude
import Refined hiding (NonEmpty)
import System.Random
import Prelude (fail)
-- | All FFI exported names in this module must have this opaque type
-- , must be followed by "Export", and must not use reserved symbols
-- like "stdout" or "stdin".
type Ex = CString -> IO CString
----------------------------- Exp3 -------------------------------------------
foreign export ccall initExp3Export :: Ex
foreign export ccall stepExp3Export :: Ex
exp3 :: Exportable (Exp3 Int) Int Int Double
exp3 =
exportBandit
(\count -> Right $ Arms (nub $ fromList [1 .. count]))
refine
initExp3Export = exportIO (initExportable exp3)
stepExp3Export = exportIO (stepExportable exp3)
deriving instance MessagePack (Arms Int)
deriving instance MessagePack (Exp3 Int)
deriving instance MessagePack (Weight Int)
deriving instance MessagePack Probability
deriving instance MessagePack CumulativeLoss
instance (MessagePack a) => MessagePack (NonEmpty a) where
toObject = toObject . Protolude.toList
fromObject x =
fromObject x >>= \y ->
case nonEmpty y of
Nothing -> fail "NonEmpty error in msgpack message"
Just t -> return t
----- typeclass based exporting functions
data Exportable b hyper a loss
= Exportable
{ initExportable :: hyper -> IO (b, a),
stepExportable :: b -> loss -> IO (b, a)
}
exportBandit ::
(Bandit b hyper a loss) =>
(hyper' -> Either e1 hyper) ->
(loss' -> Either e2 loss) ->
Exportable b hyper' a loss'
exportBandit hyperBuilder lossBuilder =
Exportable
{ initExportable = \hyper' -> hyperBuilder hyper' & \case
Left _ -> fail "hyperparameter refinement failed"
Right hyper -> do
g <- liftIO getStdGen
let (b, a, g') = HBandit.Class.init g hyper
liftIO $ setStdGen g'
return (b, a),
stepExportable = \b loss' ->
lossBuilder loss' & \case
Left _ -> fail "loss refinement failed"
Right loss -> do
g <- liftIO getStdGen
let ((a, g'), b') = runState (HBandit.Class.step g loss) b
liftIO $ setStdGen g'
return (b', a)
}
#!/usr/bin/env nix-shell
#! nix-shell -p yq -p jq -i bash
if [ $# -eq 0 ]
then
for jobname in $(yq -r 'keys| .[]' .gitlab-ci.yml); do
if [ $jobname != "stages" ]; then
gitlab-runner exec shell $jobname
fi
done
else
gitlab-runner exec shell $1
fi
import nix/default.nix {}
{ pkgs ? import (builtins.fetchTarball
"http://nixos.org/channels/nixos-20.03/nixexprs.tar.xz") { } }:
with pkgs.lib;
let
ormolu = let
source = pkgs.fetchFromGitHub {
owner = "tweag";
repo = "ormolu";
rev = "f83f6fd1dab5ccbbdf55ee1653b24595c1d653c2";
sha256 = "1hs7ayq5d15m9kxwfmdac3p2i3s6b0cn58cm4rrqc4d447yl426y";
};
in (import source { }).ormolu;
in pkgs // rec {
dhall-to-cabal-resources = pkgs.stdenv.mkDerivation {
name = "dhall-to-cabal-resources";
src = pkgs.haskellPackages.dhall-to-cabal.src;
installPhase = "cp -r dhall $out";
};
haskellPackages = pkgs.haskellPackages.override {
overrides = self: super:
with pkgs.haskell.lib; rec {
hbandit = self.callPackage ./hbandit.nix {};
panpipe = doJailbreak super.panpipe;
lazysmallcheck2012 = null;
panhandle = doJailbreak (dontCheck (self.callCabal2nix "panhandle"
(builtins.fetchTarball
"https://github.com/freuk/panhandle/archive/master.tar.gz") { }));
};
};
inherit ormolu;
hlint = haskellPackages.hlint;
hbandit = haskellPackages.hbandit;
r-libs-site = pkgs.runCommand "r-libs-site" {
buildInputs = with pkgs; [
R
rPackages.ggplot2
rPackages.svglite
rPackages.plotly
rPackages.latex2exp
];
} "echo $R_LIBS_SITE > $out";
}
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = NRM
SOURCEDIR = .
BUILDDIR = .build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/master/config
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
# import os
# import sys
import subprocess
# -- Project information -----------------------------------------------------
project = u'HBandit'
copyright = u'2019, Argonne National Laboratory'
author = u'Argo team, Argonne National Laboratory'
# The short X.Y version
version = u''
# The full version, including alpha/beta/rc tags
release = u''
# -- General configuration ---------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = []
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
# The master toctree document.
master_doc = 'index'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path .
exclude_patterns = [u'.build', 'Thumbs.db', '.DS_Store']
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static', 'hbandit']
# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# The default sidebars (for documents that don't match any pattern) are
# defined by theme itself. Builtin themes are using these templates by
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
# 'searchbox.html']``.
#
# html_sidebars = {}
# -- Options for HTMLHelp output ---------------------------------------------
# Output file base name for HTML help builder.
htmlhelp_basename = 'HBanditDoc'
# -- Options for LaTeX output ------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'HBandit.tex', u'HBandit Documentation',
u'ANL', 'manual'),
]
# -- Options for manual page output ------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'hbandit', u'HBandit Documentation',
[author], 1)
]
# -- Options for Texinfo output ----------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'HBandit', u'HBandit Documentation',
author, 'HBandit', 'Haskell Bandit Algorithms.',
'Miscellaneous'),
]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>FFI.TypeUncurry.DataKinds</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><link rel="stylesheet" type="text/css" href="quick-jump.css" /><script src="haddock-bundle.min.js" async="async" type="text/javascript"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">hbandit</p></div><div id="content"><div id="module-header"><table class="info"><tr><th valign="top">Copyright</th><td>Copyright (c) 2018 Niklas Hamb&#252;chen.</td></tr><tr><th>License</th><td>MIT License.</td></tr><tr><th>Safe Haskell</th><td>Safe</td></tr><tr><th>Language</th><td>Haskell2010</td></tr></table><p class="caption">FFI.TypeUncurry.DataKinds</p></div><div id="description"><p class="caption">Description</p><div class="doc"><p>MessagePack FFI code adapted from call-haskell-from-anything</p></div></div><div id="synopsis"><details id="syn"><summary>Synopsis</summary><ul class="details-toggle" data-details-id="syn"><li class="src short"><span class="keyword">data</span> <a href="#t:TypeList">TypeList</a> l <span class="keyword">where</span><ul class="subs"><li><a href="#v:Nil">Nil</a> :: <a href="FFI-TypeUncurry-DataKinds.html#t:TypeList" title="FFI.TypeUncurry.DataKinds">TypeList</a> '[]</li><li><a href="#v::::">(:::)</a> :: a -&gt; <a href="FFI-TypeUncurry-DataKinds.html#t:TypeList" title="FFI.TypeUncurry.DataKinds">TypeList</a> l -&gt; <a href="FFI-TypeUncurry-DataKinds.html#t:TypeList" title="FFI.TypeUncurry.DataKinds">TypeList</a> (a ': l)</li></ul></li><li class="src short"><span class="keyword">class</span> <a href="#t:ParamLength">ParamLength</a> (l :: [*]) <span class="keyword">where</span><ul class="subs"><li><a href="#v:paramLength">paramLength</a> :: <a href="&quot;https://hackage.haskell.org/package/\base-\4.12.0.0/docs&quot;/Data-Proxy.html#t:Proxy" title="Data.Proxy">Proxy</a> l -&gt; <a href="&quot;https://hackage.haskell.org/package/\base-\4.12.0.0/docs&quot;/Data-Int.html#t:Int" title="Data.Int">Int</a></li></ul></li><li class="src short"><span class="keyword">class</span> (Param f ~ l, Result f ~ r) =&gt; <a href="#t:ToTypeList">ToTypeList</a> f l r <span class="keyword">where</span><ul class="subs"><li><a href="#v:translate">translate</a> :: f -&gt; <a href="FFI-TypeUncurry-DataKinds.html#t:TypeList" title="FFI.TypeUncurry.DataKinds">TypeList</a> l -&gt; r</li></ul></li></ul></details></div><div id="interface"><h1>Documentation</h1><div class="top"><p class="src"><span class="keyword">data</span> <a id="t:TypeList" class="def">TypeList</a> l <span class="keyword">where</span> <a href="#t:TypeList" class="selflink">#</a></p><div class="doc"><p>Type-level list that can contain arbitrarily mixed types.</p><p>Example:</p><pre>1 ::: &quot;hello&quot; ::: 2.3 :: TypeList '[Int, String, Double]</pre></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a id="v:Nil" class="def">Nil</a> :: <a href="FFI-TypeUncurry-DataKinds.html#t:TypeList" title="FFI.TypeUncurry.DataKinds">TypeList</a> '[]</td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a id="v::::" class="def">(:::)</a> :: a -&gt; <a href="FFI-TypeUncurry-DataKinds.html#t:TypeList" title="FFI.TypeUncurry.DataKinds">TypeList</a> l -&gt; <a href="FFI-TypeUncurry-DataKinds.html#t:TypeList" title="FFI.TypeUncurry.DataKinds">TypeList</a> (a ': l) <span class="fixity">infixr 9</span><span class="rightedge"></span></td><td class="doc empty">&nbsp;</td></tr></table></div><div class="subs instances"><details id="i:TypeList" open="open"><summary>Instances</summary><table><tr><td class="src clearfix"><span class="inst-left"><span class="instance details-toggle-control details-toggle" data-details-id="i:id:TypeList:MessagePack:1"></span> (<a href="FFI-TypeUncurry-Msgpack.html#t:MessagePackRec" title="FFI.TypeUncurry.Msgpack">MessagePackRec</a> l, <a href="FFI-TypeUncurry-DataKinds.html#t:ParamLength" title="FFI.TypeUncurry.DataKinds">ParamLength</a> l) =&gt; <a href="&quot;https://hackage.haskell.org/package/\data-msgpack-types-\0.0.2/docs&quot;/Data-MessagePack-Types-Class.html#t:MessagePack" title="Data.MessagePack.Types.Class">MessagePack</a> (<a href="FFI-TypeUncurry-DataKinds.html#t:TypeList" title="FFI.TypeUncurry.DataKinds">TypeList</a> l)</span> <a href="#t:MessagePack" class="selflink">#</a></td><td class="doc empty">&nbsp;</td></tr><tr><td colspan="2"><details id="i:id:TypeList:MessagePack:1"><summary class="hide-when-js-enabled">Instance details</summary><p>Defined in <a href="FFI-TypeUncurry-Msgpack.html">FFI.TypeUncurry.Msgpack</a></p> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:toObject">toObject</a> :: <a href="FFI-TypeUncurry-DataKinds.html#t:TypeList" title="FFI.TypeUncurry.DataKinds">TypeList</a> l -&gt; <a href="&quot;https://hackage.haskell.org/package/\data-msgpack-types-\0.0.2/docs&quot;/Data-MessagePack-Types-Object.html#t:Object" title="Data.MessagePack.Types.Object">Object</a> <a href="#v:toObject" class="selflink">#</a></p><p class="src"><a href="#v:fromObject">fromObject</a> :: (<a href="&quot;https://hackage.haskell.org/package/\base-\4.12.0.0/docs&quot;/Control-Applicative.html#t:Applicative" title="Control.Applicative">Applicative</a> m, <a href="&quot;https://hackage.haskell.org/package/\base-\4.12.0.0/docs&quot;/Control-Monad.html#t:Monad" title="Control.Monad">Monad</a> m) =&gt; <a href="&quot;https://hackage.haskell.org/package/\data-msgpack-types-\0.0.2/docs&quot;/Data-MessagePack-Types-Object.html#t:Object" title="Data.MessagePack.Types.Object">Object</a> -&gt; m (<a href="FFI-TypeUncurry-DataKinds.html#t:TypeList" title="FFI.TypeUncurry.DataKinds">TypeList</a> l) <a href="#v:fromObject" class="selflink">#</a></p></div></details></td></tr></table></details></div></div><div class="top"><p class="src"><span class="keyword">class</span> <a id="t:ParamLength" class="def">ParamLength</a> (l :: [*]) <span class="keyword">where</span> <a href="#t:ParamLength" class="selflink">#</a></p><div class="doc"><p>Allows to calculate the length of a <code><a href="FFI-TypeUncurry-DataKinds.html#t:TypeList" title="FFI.TypeUncurry.DataKinds">TypeList</a></code>, at compile time.</p><p>We need to use a <code><a href="&quot;https://hackage.haskell.org/package/\base-\4.12.0.0/docs&quot;/Data-Proxy.html#t:Proxy" title="Data.Proxy">Proxy</a></code> for this.</p></div><div class="subs methods"><p class="caption">Methods</p><p class="src"><a id="v:paramLength" class="def">paramLength</a> :: <a href="&quot;https://hackage.haskell.org/package/\base-\4.12.0.0/docs&quot;/Data-Proxy.html#t:Proxy" title="Data.Proxy">Proxy</a> l -&gt; <a href="&quot;https://hackage.haskell.org/package/\base-\4.12.0.0/docs&quot;/Data-Int.html#t:Int" title="Data.Int">Int</a> <a href="#v:paramLength" class="selflink">#</a></p><div class="doc"><p>Calculates the length of a type list, put into a proxy. Usage:</p><pre>paramLength (Proxy :: Proxy l)</pre></div></div><div class="subs instances"><details id="i:ParamLength" open="open"><summary>Instances</summary><table><tr><td class="src clearfix"><span class="inst-left"><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:ParamLength:ParamLength:1"></span> <a href="FFI-TypeUncurry-DataKinds.html#t:ParamLength" title="FFI.TypeUncurry.DataKinds">ParamLength</a> ([] :: [<a href="&quot;https://hackage.haskell.org/package/\base-\4.12.0.0/docs&quot;/Data-Kind.html#t:Type" title="Data.Kind">Type</a>])</span> <a href="#t:ParamLength" class="selflink">#</a></td><td class="doc empty">&nbsp;</td></tr><tr><td colspan="2"><details id="i:ic:ParamLength:ParamLength:1"><summary class="hide-when-js-enabled">Instance details</summary><p>Defined in <a href="FFI-TypeUncurry-DataKinds.html">FFI.TypeUncurry.DataKinds</a></p> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:paramLength">paramLength</a> :: <a href="&quot;https://hackage.haskell.org/package/\base-\4.12.0.0/docs&quot;/Data-Proxy.html#t:Proxy" title="Data.Proxy">Proxy</a> [] -&gt; <a href="&quot;https://hackage.haskell.org/package/\base-\4.12.0.0/docs&quot;/Data-Int.html#t:Int" title="Data.Int">Int</a> <a href="#v:paramLength" class="selflink">#</a></p></div></details></td></tr><tr><td class="src clearfix"><span class="inst-left"><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:ParamLength:ParamLength:2"></span> <a href="FFI-TypeUncurry-DataKinds.html#t:ParamLength" title="FFI.TypeUncurry.DataKinds">ParamLength</a> l =&gt; <a href="FFI-TypeUncurry-DataKinds.html#t:ParamLength" title="FFI.TypeUncurry.DataKinds">ParamLength</a> (a ': l)</span> <a href="#t:ParamLength" class="selflink">#</a></td><td class="doc empty">&nbsp;</td></tr><tr><td colspan="2"><details id="i:ic:ParamLength:ParamLength:2"><summary class="hide-when-js-enabled">Instance details</summary><p>Defined in <a href="FFI-TypeUncurry-DataKinds.html">FFI.TypeUncurry.DataKinds</a></p> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:paramLength">paramLength</a> :: <a href="&quot;https://hackage.haskell.org/package/\base-\4.12.0.0/docs&quot;/Data-Proxy.html#t:Proxy" title="Data.Proxy">Proxy</a> (a ': l) -&gt; <a href="&quot;https://hackage.haskell.org/package/\base-\4.12.0.0/docs&quot;/Data-Int.html#t:Int" title="Data.Int">Int</a> <a href="#v:paramLength" class="selflink">#</a></p></div></details></td></tr></table></details></div></div><div class="top"><p class="src"><span class="keyword">class</span> (Param f ~ l, Result f ~ r) =&gt; <a id="t:ToTypeList" class="def">ToTypeList</a> f l r <span class="keyword">where</span> <a href="#t:ToTypeList" class="selflink">#</a></p><div class="doc"><p>Function f can be translated to <code><a href="FFI-TypeUncurry-DataKinds.html#t:TypeList" title="FFI.TypeUncurry.DataKinds">TypeList</a></code> l with result type r.</p></div><div class="subs methods"><p class="caption">Methods</p><p class="src"><a id="v:translate" class="def">translate</a> :: f -&gt; <a href="FFI-TypeUncurry-DataKinds.html#t:TypeList" title="FFI.TypeUncurry.DataKinds">TypeList</a> l -&gt; r <a href="#v:translate" class="selflink">#</a></p><div class="doc"><p>Translates a function taking multiple arguments to a function
taking a single <code><a href="FFI-TypeUncurry-DataKinds.html#t:TypeList" title="FFI.TypeUncurry.DataKinds">TypeList</a></code> containing the types of all arguments.</p><p>Example: <code>t1 -&gt; ... -&gt; tn -&gt; r</code> becomes <code>TypeList [t1, ..., tn] -&gt; r</code>.</p></div></div><div class="subs instances"><details id="i:ToTypeList" open="open"><summary>Instances</summary><table><tr><td class="src clearfix"><span class="inst-left"><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:ToTypeList:ToTypeList:1"></span> (Param f ~ ([] :: [<a href="&quot;https://hackage.haskell.org/package/\base-\4.12.0.0/docs&quot;/Data-Kind.html#t:Type" title="Data.Kind">Type</a>]), Result f ~ r, f ~ r) =&gt; <a href="FFI-TypeUncurry-DataKinds.html#t:ToTypeList" title="FFI.TypeUncurry.DataKinds">ToTypeList</a> f ([] :: [<a href="&quot;https://hackage.haskell.org/package/\base-\4.12.0.0/docs&quot;/Data-Kind.html#t:Type" title="Data.Kind">Type</a>]) r</span> <a href="#t:ToTypeList" class="selflink">#</a></td><td class="doc"><p>Base case: A value <code>r</code> can be translated to <code>TypeList Nil -&gt; r</code>.</p></td></tr><tr><td colspan="2"><details id="i:ic:ToTypeList:ToTypeList:1"><summary class="hide-when-js-enabled">Instance details</summary><p>Defined in <a href="FFI-TypeUncurry-DataKinds.html">FFI.TypeUncurry.DataKinds</a></p> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:translate">translate</a> :: f -&gt; <a href="FFI-TypeUncurry-DataKinds.html#t:TypeList" title="FFI.TypeUncurry.DataKinds">TypeList</a> [] -&gt; r <a href="#v:translate" class="selflink">#</a></p></div></details></td></tr><tr><td class="src clearfix"><span class="inst-left"><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:ToTypeList:ToTypeList:2"></span> <a href="FFI-TypeUncurry-DataKinds.html#t:ToTypeList" title="FFI.TypeUncurry.DataKinds">ToTypeList</a> f l r =&gt; <a href="FFI-TypeUncurry-DataKinds.html#t:ToTypeList" title="FFI.TypeUncurry.DataKinds">ToTypeList</a> (a -&gt; f) (a ': l) r</span> <a href="#t:ToTypeList" class="selflink">#</a></td><td class="doc"><p>Base case: A &quot;pure&quot; function without arguments
can be translated to <code>TypeList Nil -&gt; r</code>.</p></td></tr><tr><td colspan="2"><details id="i:ic:ToTypeList:ToTypeList:2"><summary class="hide-when-js-enabled">Instance details</summary><p>Defined in <a href="FFI-TypeUncurry-DataKinds.html">FFI.TypeUncurry.DataKinds</a></p> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:translate">translate</a> :: (a -&gt; f) -&gt; <a href="FFI-TypeUncurry-DataKinds.html#t:TypeList" title="FFI.TypeUncurry.DataKinds">TypeList</a> (a ': l) -&gt; r <a href="#v:translate" class="selflink">#</a></p></div></details></td></tr></table></details></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.22.0</p></div></body></html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>FFI.TypeUncurry.Msgpack</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><link rel="stylesheet" type="text/css" href="quick-jump.css" /><script src="haddock-bundle.min.js" async="async" type="text/javascript"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">hbandit</p></div><div id="content"><div id="module-header"><table class="info"><tr><th valign="top">Copyright</th><td>Copyright (c) 2018 Niklas Hamb&#252;chen.</td></tr><tr><th>License</th><td>MIT License.</td></tr><tr><th>Safe Haskell</th><td>None</td></tr><tr><th>Language</th><td>Haskell2010</td></tr></table><p class="caption">FFI.TypeUncurry.Msgpack</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#section.orphans">Orphan instances</a></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>MessagePack FFI code adapted from call-haskell-from-anything</p></div></div><div id="synopsis"><details id="syn"><summary>Synopsis</summary><ul class="details-toggle" data-details-id="syn"><li class="src short"><span class="keyword">class</span> <a href="#t:MessagePackRec">MessagePackRec</a> l <span class="keyword">where</span><ul class="subs"><li><a href="#v:fromObjectRec">fromObjectRec</a> :: <a href="&quot;https://hackage.haskell.org/package/\base-\4.12.0.0/docs&quot;/Control-Monad.html#t:Monad" title="Control.Monad">Monad</a> m =&gt; [<a href="&quot;https://hackage.haskell.org/package/\data-msgpack-types-\0.0.2/docs&quot;/Data-MessagePack-Types-Object.html#t:Object" title="Data.MessagePack.Types.Object">Object</a>] -&gt; m (<a href="FFI-TypeUncurry-DataKinds.html#t:TypeList" title="FFI.TypeUncurry.DataKinds">TypeList</a> l)</li></ul></li><li class="src short"><a href="#v:getTypeListFromMsgpackArray">getTypeListFromMsgpackArray</a> :: <span class="keyword">forall</span> m l. (<a href="FFI-TypeUncurry-Msgpack.html#t:MessagePackRec" title="FFI.TypeUncurry.Msgpack">MessagePackRec</a> l, <a href="FFI-TypeUncurry-DataKinds.html#t:ParamLength"</