Skip to content

Commit

Permalink
Playing with arbitrary data and testing instances
Browse files Browse the repository at this point in the history
  • Loading branch information
Anastasios Valtinos committed Oct 14, 2022
1 parent 64289ae commit 934df9e
Show file tree
Hide file tree
Showing 28 changed files with 322 additions and 25 deletions.

This file was deleted.

29 changes: 29 additions & 0 deletions Haskell Excercises & Code/Chapter25 - Composing Types/EitherTT.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module EitherTT where

import Test.QuickCheck
-- newtype MaybeT m a =
-- MaybeT { runMaybeT :: m (Maybe a) }


newtype EitherT e m a = EitherT { runEitherT :: m (Either e a) }

newtype TestData a b = TestData b deriving (Eq, Show)

-- Github Arbitrary example
-- instance Arbitrary Cell where
-- arbitrary = do
-- Positive x <- arbitrary
-- Positive y <- arbitrary
-- return $ Cell x y

-- arbitrary :: Gen a
genArbit :: (Arbitrary a, Arbitrary b) => Gen (TestData a b)
genArbit = do
x1 <- arbitrary
return $ TestData x1

randomGen = sample' (genArbit :: Gen (TestData Int Int))

-- 1. Write the Functor instance for EitherT:
instance Functor m => Functor (EitherT e m) where
fmap f (EitherT ema) = EitherT $ (fmap . fmap) f ema
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ instance (Applicative f, Applicative g) => Applicative (Compose f g) where
--(<*>) :: Compose f g (a -> b) -> Compose f g a -> Compose f g b
-- this is wrong
-- (Compose f) <*> (Compose a) = Compose $ (fmap <*> f) <*> a
Compose f <*> Compose x = Compose ((<*>) <$> f <*> x)

instance (Foldable f, Foldable g) => Foldable (Compose f g) where
foldMap f (Compose fga) = (foldMap . foldMap) f fga
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: composing
version: 0.1.0.0
license-file: LICENSE
author: Chicken Little
maintainer: sky@isfalling.org
category: Text
build-type: Simple
cabal-version: >=1.10

library
exposed-modules: EitherTT
ghc-options: -Wall -fwarn-tabs
build-depends: base >=4.7 && <5
, hspec
, QuickCheck
hs-source-dirs: .
default-language: Haskell2010
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE NoRebindableSyntax #-}
{-# OPTIONS_GHC -fno-warn-missing-import-lists #-}
{-# OPTIONS_GHC -w #-}
module Paths_composing (
version,
getBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir,
getDataFileName, getSysconfDir
) where


import qualified Control.Exception as Exception
import qualified Data.List as List
import Data.Version (Version(..))
import System.Environment (getEnv)
import Prelude


#if defined(VERSION_base)

#if MIN_VERSION_base(4,0,0)
catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a
#else
catchIO :: IO a -> (Exception.Exception -> IO a) -> IO a
#endif

#else
catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a
#endif
catchIO = Exception.catch

version :: Version
version = Version [0,1,0,0] []

getDataFileName :: FilePath -> IO FilePath
getDataFileName name = do
dir <- getDataDir
return (dir `joinFileName` name)

getBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir, getSysconfDir :: IO FilePath



bindir, libdir, dynlibdir, datadir, libexecdir, sysconfdir :: FilePath
bindir = "C:\\Users\\Administrator\\AppData\\Roaming\\cabal\\bin"
libdir = "C:\\Users\\Administrator\\AppData\\Roaming\\cabal\\x86_64-windows-ghc-9.2.1\\composing-0.1.0.0-inplace"
dynlibdir = "C:\\Users\\Administrator\\AppData\\Roaming\\cabal\\x86_64-windows-ghc-9.2.1"
datadir = "C:\\Users\\Administrator\\AppData\\Roaming\\cabal\\x86_64-windows-ghc-9.2.1\\composing-0.1.0.0"
libexecdir = "C:\\Users\\Administrator\\AppData\\Roaming\\cabal\\composing-0.1.0.0-inplace\\x86_64-windows-ghc-9.2.1\\composing-0.1.0.0"
sysconfdir = "C:\\Users\\Administrator\\AppData\\Roaming\\cabal\\etc"

getBinDir = catchIO (getEnv "composing_bindir") (\_ -> return bindir)
getLibDir = catchIO (getEnv "composing_libdir") (\_ -> return libdir)
getDynLibDir = catchIO (getEnv "composing_dynlibdir") (\_ -> return dynlibdir)
getDataDir = catchIO (getEnv "composing_datadir") (\_ -> return datadir)
getLibexecDir = catchIO (getEnv "composing_libexecdir") (\_ -> return libexecdir)
getSysconfDir = catchIO (getEnv "composing_sysconfdir") (\_ -> return sysconfdir)




joinFileName :: String -> String -> FilePath
joinFileName "" fname = fname
joinFileName "." fname = fname
joinFileName dir "" = dir
joinFileName dir fname
| isPathSeparator (List.last dir) = dir ++ fname
| otherwise = dir ++ pathSeparator : fname

pathSeparator :: Char
pathSeparator = '\\'

isPathSeparator :: Char -> Bool
isPathSeparator c = c == '/' || c == '\\'
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/* DO NOT EDIT: This file is automatically generated by Cabal */

/* package composing-0.1.0.0 */
#ifndef VERSION_composing
#define VERSION_composing "0.1.0.0"
#endif /* VERSION_composing */
#ifndef MIN_VERSION_composing
#define MIN_VERSION_composing(major1,major2,minor) (\
(major1) < 0 || \
(major1) == 0 && (major2) < 1 || \
(major1) == 0 && (major2) == 1 && (minor) <= 0)
#endif /* MIN_VERSION_composing */
/* package QuickCheck-2.14.2 */
#ifndef VERSION_QuickCheck
#define VERSION_QuickCheck "2.14.2"
#endif /* VERSION_QuickCheck */
#ifndef MIN_VERSION_QuickCheck
#define MIN_VERSION_QuickCheck(major1,major2,minor) (\
(major1) < 2 || \
(major1) == 2 && (major2) < 14 || \
(major1) == 2 && (major2) == 14 && (minor) <= 2)
#endif /* MIN_VERSION_QuickCheck */
/* package base-4.16.0.0 */
#ifndef VERSION_base
#define VERSION_base "4.16.0.0"
#endif /* VERSION_base */
#ifndef MIN_VERSION_base
#define MIN_VERSION_base(major1,major2,minor) (\
(major1) < 4 || \
(major1) == 4 && (major2) < 16 || \
(major1) == 4 && (major2) == 16 && (minor) <= 0)
#endif /* MIN_VERSION_base */
/* package hspec-2.10.6 */
#ifndef VERSION_hspec
#define VERSION_hspec "2.10.6"
#endif /* VERSION_hspec */
#ifndef MIN_VERSION_hspec
#define MIN_VERSION_hspec(major1,major2,minor) (\
(major1) < 2 || \
(major1) == 2 && (major2) < 10 || \
(major1) == 2 && (major2) == 10 && (minor) <= 6)
#endif /* MIN_VERSION_hspec */

/* tool gcc-10.2.0 */
#ifndef TOOL_VERSION_gcc
#define TOOL_VERSION_gcc "10.2.0"
#endif /* TOOL_VERSION_gcc */
#ifndef MIN_TOOL_VERSION_gcc
#define MIN_TOOL_VERSION_gcc(major1,major2,minor) (\
(major1) < 10 || \
(major1) == 10 && (major2) < 2 || \
(major1) == 10 && (major2) == 2 && (minor) <= 0)
#endif /* MIN_TOOL_VERSION_gcc */
/* tool ghc-9.2.1 */
#ifndef TOOL_VERSION_ghc
#define TOOL_VERSION_ghc "9.2.1"
#endif /* TOOL_VERSION_ghc */
#ifndef MIN_TOOL_VERSION_ghc
#define MIN_TOOL_VERSION_ghc(major1,major2,minor) (\
(major1) < 9 || \
(major1) == 9 && (major2) < 2 || \
(major1) == 9 && (major2) == 2 && (minor) <= 1)
#endif /* MIN_TOOL_VERSION_ghc */
/* tool ghc-pkg-9.2.1 */
#ifndef TOOL_VERSION_ghc_pkg
#define TOOL_VERSION_ghc_pkg "9.2.1"
#endif /* TOOL_VERSION_ghc_pkg */
#ifndef MIN_TOOL_VERSION_ghc_pkg
#define MIN_TOOL_VERSION_ghc_pkg(major1,major2,minor) (\
(major1) < 9 || \
(major1) == 9 && (major2) < 2 || \
(major1) == 9 && (major2) == 2 && (minor) <= 1)
#endif /* MIN_TOOL_VERSION_ghc_pkg */
/* tool haddock-2.26.0 */
#ifndef TOOL_VERSION_haddock
#define TOOL_VERSION_haddock "2.26.0"
#endif /* TOOL_VERSION_haddock */
#ifndef MIN_TOOL_VERSION_haddock
#define MIN_TOOL_VERSION_haddock(major1,major2,minor) (\
(major1) < 2 || \
(major1) == 2 && (major2) < 26 || \
(major1) == 2 && (major2) == 26 && (minor) <= 0)
#endif /* MIN_TOOL_VERSION_haddock */
/* tool hpc-0.68 */
#ifndef TOOL_VERSION_hpc
#define TOOL_VERSION_hpc "0.68"
#endif /* TOOL_VERSION_hpc */
#ifndef MIN_TOOL_VERSION_hpc
#define MIN_TOOL_VERSION_hpc(major1,major2,minor) (\
(major1) < 0 || \
(major1) == 0 && (major2) < 68 || \
(major1) == 0 && (major2) == 68 && (minor) <= 0)
#endif /* MIN_TOOL_VERSION_hpc */
/* tool hsc2hs-0.68.8 */
#ifndef TOOL_VERSION_hsc2hs
#define TOOL_VERSION_hsc2hs "0.68.8"
#endif /* TOOL_VERSION_hsc2hs */
#ifndef MIN_TOOL_VERSION_hsc2hs
#define MIN_TOOL_VERSION_hsc2hs(major1,major2,minor) (\
(major1) < 0 || \
(major1) == 0 && (major2) < 68 || \
(major1) == 0 && (major2) == 68 && (minor) <= 8)
#endif /* MIN_TOOL_VERSION_hsc2hs */
/* tool runghc-9.2.1 */
#ifndef TOOL_VERSION_runghc
#define TOOL_VERSION_runghc "9.2.1"
#endif /* TOOL_VERSION_runghc */
#ifndef MIN_TOOL_VERSION_runghc
#define MIN_TOOL_VERSION_runghc(major1,major2,minor) (\
(major1) < 9 || \
(major1) == 9 && (major2) < 2 || \
(major1) == 9 && (major2) == 2 && (minor) <= 1)
#endif /* MIN_TOOL_VERSION_runghc */
/* tool strip-2.34 */
#ifndef TOOL_VERSION_strip
#define TOOL_VERSION_strip "2.34"
#endif /* TOOL_VERSION_strip */
#ifndef MIN_TOOL_VERSION_strip
#define MIN_TOOL_VERSION_strip(major1,major2,minor) (\
(major1) < 2 || \
(major1) == 2 && (major2) < 34 || \
(major1) == 2 && (major2) == 34 && (minor) <= 0)
#endif /* MIN_TOOL_VERSION_strip */

#ifndef CURRENT_PACKAGE_KEY
#define CURRENT_PACKAGE_KEY "composing-0.1.0.0-inplace"
#endif /* CURRENT_packageKey */
#ifndef CURRENT_COMPONENT_ID
#define CURRENT_COMPONENT_ID "composing-0.1.0.0-inplace"
#endif /* CURRENT_COMPONENT_ID */
#ifndef CURRENT_PACKAGE_VERSION
#define CURRENT_PACKAGE_VERSION "0.1.0.0"
#endif /* CURRENT_PACKAGE_VERSION */
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: composing
version: 0.1.0.0
visibility: public
id: composing-0.1.0.0-inplace
key: composing-0.1.0.0-inplace
maintainer: sky@isfalling.org
author: Chicken Little
category: Text
abi: inplace
exposed: True
exposed-modules: EitherTT
import-dirs:
"C:\\Users\\Administrator\\Desktop\\Haskell first Principles\\haskell-deepidive\\Haskell Excercises & Code\\Chapter25 - Composing Types\\dist-newstyle\\build\\x86_64-windows\\ghc-9.2.1\\composing-0.1.0.0\\build"

library-dirs:
"C:\\Users\\Administrator\\Desktop\\Haskell first Principles\\haskell-deepidive\\Haskell Excercises & Code\\Chapter25 - Composing Types\\dist-newstyle\\build\\x86_64-windows\\ghc-9.2.1\\composing-0.1.0.0\\build"

dynamic-library-dirs:
"C:\\Users\\Administrator\\Desktop\\Haskell first Principles\\haskell-deepidive\\Haskell Excercises & Code\\Chapter25 - Composing Types\\dist-newstyle\\build\\x86_64-windows\\ghc-9.2.1\\composing-0.1.0.0\\build"

data-dir:
"C:\\Users\\Administrator\\Desktop\\Haskell first Principles\\haskell-deepidive\\Haskell Excercises & Code\\Chapter25 - Composing Types\\."

hs-libraries: HScomposing-0.1.0.0-inplace
include-dirs: C:\tools\msys64\mingw64\include
depends:
QuickCheck-2.14.2-a86079fca27e4995eff71586bc69486728d69c5d
base-4.16.0.0 hspec-2.10.6-4755191b26c19bdcaf316d380b729c36bd3ac94c

haddock-interfaces:
"C:\\Users\\Administrator\\Desktop\\Haskell first Principles\\haskell-deepidive\\Haskell Excercises & Code\\Chapter25 - Composing Types\\dist-newstyle\\build\\x86_64-windows\\ghc-9.2.1\\composing-0.1.0.0\\doc\\html\\composing\\composing.haddock"

haddock-html:
"C:\\Users\\Administrator\\Desktop\\Haskell first Principles\\haskell-deepidive\\Haskell Excercises & Code\\Chapter25 - Composing Types\\dist-newstyle\\build\\x86_64-windows\\ghc-9.2.1\\composing-0.1.0.0\\doc\\html\\composing"
Binary file not shown.
30 changes: 30 additions & 0 deletions Haskell Excercises & Code/Chapter25 - Composing Types/hasky.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Lines should be no longer than this length in characters.
line_length_limit: 80

# How much to spread code over multiple lines instead of trying to fill a single
# line. More precisely, this guides the ratio of "line_length_limit" to the
# ribbon length (the number of characters on a line without leading and trailing
# whitespace). Only the lowest value of 1 forces "line_length_limit" to be
# applied strictly.
# Reference: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.38.8777
ribbons_per_line: 1

# More than this number of empty lines in succession are merged.
successive_empty_lines_limit: 1

# Indentation lengths in characters.
indentations:
class: 8 # "class" and "instance" declarations.
do: 3 # "do" notation.
case: 4 # Body of "case" expressions.
let: 4 # Declarations in "let" expressions.
where: 6 # Declarations in "where" clauses.
onside: 2 # Continuation lines which would otherwise be offside.

# Decides which parts of the code to sort.
order:
# Sequence of import declarations.
import_declarations: true

# Entities of import lists.
import_entities: true
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ newtype IdentityT f a =
IdentityT { runIdentityT :: f a }
deriving (Eq, Show)

instance Functor Identity where
instance Functor Identity where
fmap f (Identity a) = Identity (f a)

instance (Functor m) => Functor (IdentityT m) where
Expand All @@ -28,7 +28,7 @@ instance (Applicative m) => Applicative (IdentityT m) where

instance Monad Identity where
return = pure
(Identity a) >>= f = f a
(Identity a) >>= f = f a

instance (Monad m) => Monad (IdentityT m) where
return = pure
Expand All @@ -37,4 +37,4 @@ instance (Monad m) => Monad (IdentityT m) where
--f :: a -> m b
-- ma :: Monadic a
-- runIdentityT :: IdentityT m a -> m a
-- f :: a -> f a
-- f :: a -> f a

0 comments on commit 934df9e

Please sign in to comment.