├── README.md ├── .gitignore ├── Setup.hs ├── ChangeLog.md ├── test └── Spec.hs ├── src └── Lib.hs ├── package.yaml ├── LICENSE ├── stack.yaml └── app └── Main.hs /README.md: -------------------------------------------------------------------------------- 1 | # conal-ad 2 | # conal-ad 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .stack-work/ 2 | conal-ad.cabal 3 | *~ -------------------------------------------------------------------------------- /Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /ChangeLog.md: -------------------------------------------------------------------------------- 1 | # Changelog for conal-ad 2 | 3 | ## Unreleased changes 4 | -------------------------------------------------------------------------------- /test/Spec.hs: -------------------------------------------------------------------------------- 1 | main :: IO () 2 | main = putStrLn "Test suite not yet implemented" 3 | -------------------------------------------------------------------------------- /src/Lib.hs: -------------------------------------------------------------------------------- 1 | module Lib 2 | ( someFunc 3 | ) where 4 | 5 | someFunc :: IO () 6 | someFunc = putStrLn "someFunc" 7 | -------------------------------------------------------------------------------- /package.yaml: -------------------------------------------------------------------------------- 1 | name: conal-ad 2 | version: 0.1.0.0 3 | github: "githubuser/conal-ad" 4 | license: BSD3 5 | author: "Author name here" 6 | maintainer: "example@example.com" 7 | copyright: "2018 Author name here" 8 | 9 | extra-source-files: 10 | - README.md 11 | - ChangeLog.md 12 | 13 | # Metadata used when publishing your package 14 | # synopsis: Short description of your package 15 | # category: Web 16 | 17 | # To avoid duplicated efforts in documentation and dealing with the 18 | # complications of embedding Haddock markup inside cabal files, it is 19 | # common to point users to the README.md file. 20 | description: Please see the README on Github at 21 | 22 | dependencies: 23 | - base >= 4.7 && < 5 24 | 25 | library: 26 | source-dirs: src 27 | 28 | executables: 29 | conal-ad-exe: 30 | main: Main.hs 31 | source-dirs: app 32 | ghc-options: 33 | - -threaded 34 | - -rtsopts 35 | - -with-rtsopts=-N 36 | dependencies: 37 | - conal-ad 38 | - constrained-categories 39 | 40 | tests: 41 | conal-ad-test: 42 | main: Spec.hs 43 | source-dirs: test 44 | ghc-options: 45 | - -threaded 46 | - -rtsopts 47 | - -with-rtsopts=-N 48 | dependencies: 49 | - conal-ad 50 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright Author name here (c) 2018 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following 13 | disclaimer in the documentation and/or other materials provided 14 | with the distribution. 15 | 16 | * Neither the name of Author name here nor the names of other 17 | contributors may be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /stack.yaml: -------------------------------------------------------------------------------- 1 | # This file was automatically generated by 'stack init' 2 | # 3 | # Some commonly used options have been documented as comments in this file. 4 | # For advanced use and comprehensive documentation of the format, please see: 5 | # https://docs.haskellstack.org/en/stable/yaml_configuration/ 6 | 7 | # Resolver to choose a 'specific' stackage snapshot or a compiler version. 8 | # A snapshot resolver dictates the compiler version and the set of packages 9 | # to be used for project dependencies. For example: 10 | # 11 | # resolver: lts-3.5 12 | # resolver: nightly-2015-09-21 13 | # resolver: ghc-7.10.2 14 | # resolver: ghcjs-0.1.0_ghc-7.10.2 15 | # resolver: 16 | # name: custom-snapshot 17 | # location: "./custom-snapshot.yaml" 18 | resolver: lts-11.2 19 | 20 | # User packages to be built. 21 | # Various formats can be used as shown in the example below. 22 | # 23 | # packages: 24 | # - some-directory 25 | # - https://example.com/foo/bar/baz-0.0.2.tar.gz 26 | # - location: 27 | # git: https://github.com/commercialhaskell/stack.git 28 | # commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a 29 | # - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a 30 | # extra-dep: true 31 | # subdirs: 32 | # - auto-update 33 | # - wai 34 | # 35 | # A package marked 'extra-dep: true' will only be built if demanded by a 36 | # non-dependency (i.e. a user package), and its test suites and benchmarks 37 | # will not be run. This is useful for tweaking upstream packages. 38 | packages: 39 | - . 40 | # Dependency packages to be pulled from upstream that are not in the resolver 41 | # (e.g., acme-missiles-0.3) 42 | extra-deps: 43 | - constrained-categories-0.3.1.0 44 | 45 | # Override default flag values for local packages and extra-deps 46 | # flags: {} 47 | 48 | # Extra package databases containing global packages 49 | # extra-package-dbs: [] 50 | 51 | # Control whether we use the GHC we find on the path 52 | # system-ghc: true 53 | # 54 | # Require a specific version of stack, using version ranges 55 | # require-stack-version: -any # Default 56 | # require-stack-version: ">=1.6" 57 | # 58 | # Override the architecture used by stack, especially useful on Windows 59 | # arch: i386 60 | # arch: x86_64 61 | # 62 | # Extra directories used by stack for building 63 | # extra-include-dirs: [/path/to/dir] 64 | # extra-lib-dirs: [/path/to/dir] 65 | # 66 | # Allow a newer minor version of GHC than the snapshot specifies 67 | # compiler-check: newer-minor -------------------------------------------------------------------------------- /app/Main.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE ConstraintKinds, TypeFamilies, FlexibleInstances, MultiParamTypeClasses, NoImplicitPrelude, FlexibleContexts #-} 2 | 3 | module Main where 4 | 5 | import Lib 6 | import Control.Category.Constrained.Prelude 7 | import Control.Arrow.Constrained 8 | --import Prelude hiding (id, (.), uncurry, curry) 9 | 10 | 11 | newtype D k a b = D (a -> (b, k a b)) 12 | 13 | linearD :: (a -> b) -> (k a b) -> D k a b 14 | linearD f f' = D (\a -> (f a, f')) 15 | 16 | instance Category k => Category (D k) where 17 | type (Object (D k) o) = (Object k o) -- constraints that the objects must satisfy (Additive o, 18 | id = linearD id id 19 | (D g) . (D f) = D (\a -> let (b , f') = f a 20 | (c , g') = g b in (c, g' . f')) 21 | 22 | 23 | -- could use Kmett's Additive from the linear package, but is rank 1 24 | -- also Data.AdditiveGroup from conal's vector-space 25 | 26 | 27 | instance Cartesian k => Cartesian (D k) where 28 | type (PairObjects (D k) a b) = PairObjects k a b 29 | type UnitObject (D k) = UnitObject k 30 | swap = linearD swap swap 31 | attachUnit = linearD attachUnit attachUnit 32 | detachUnit = linearD detachUnit detachUnit 33 | regroup = linearD regroup regroup 34 | regroup' = linearD regroup' regroup' 35 | 36 | 37 | 38 | 39 | -- morphism is basically what Conal calls being Monoidal 40 | -- and *** = Big Cross 41 | instance Morphism k => Morphism (D k) where 42 | (D f) *** (D g) = D $ \(a, b) -> let (c,f') = f a 43 | (d, g') = g b in 44 | ((c,d, f' *** g')) 45 | -- paralell arrows 46 | 47 | -- exl = fst 48 | -- exr = snd 49 | -- triangle = &&& 50 | 51 | dup :: (PreArrow a, Object a b, ObjectPair a b b) => a b (b, b) 52 | dup = id &&& id 53 | 54 | instance PreArrow a => PreArrow (D a) where 55 | fst = linearD fst fst 56 | snd = linearD snd snd 57 | f &&& g = (f *** g) . dup' where dup' = linearD dup dup 58 | terminal = linearD terminal terminal 59 | 60 | 61 | 62 | class Additive o where 63 | addy :: o -> o -> o 64 | zero :: o 65 | {- 66 | instance (Num a) => Additive a where 67 | addy = (+) 68 | zero = fromInteger 0 69 | -} 70 | 71 | instance Additive Double where 72 | addy = (+) 73 | zero = fromInteger 0 74 | 75 | class NumCat k a where 76 | negateC :: k a a 77 | addC :: k (a, a) a 78 | mulC :: k (a, a) a 79 | 80 | instance Num a => NumCat (->) a where 81 | negateC = negate 82 | addC (x, y) = x + y 83 | mulC (x,y) = x * y 84 | 85 | class Scalable k a where 86 | scale :: a -> k a a 87 | 88 | --instance Num a => Scalable 89 | {- 90 | instance Scalable k s => NumCat (D k) s where 91 | negateC = linearD negateC 92 | addC = linearD addC 93 | mulC = D (\(a,b) -> (a * b, ) 94 | -} 95 | 96 | 97 | 98 | main :: IO () 99 | main = someFunc 100 | --------------------------------------------------------------------------------