├── doc
├── chapterio.tex
└── Makefile
├── resources
├── Frege_logo.jpg
├── Frege_logo.png
├── Frege_logo_flat_colours.jpg
└── Frege_logo_flat_colours.png
├── tests
├── nocomp
│ ├── Issue348.fr
│ ├── Issue286.fr
│ ├── Issue125.fr
│ ├── Issue293.fr
│ ├── Issue102.fr
│ ├── Issue47b.fr
│ ├── Issue47a.fr
│ └── Issue53.fr
├── comp
│ ├── Issue158.fr
│ ├── Dezi.fr
│ ├── Issue313.fr
│ ├── Issue260.fr
│ ├── Issue332.fr
│ ├── Issue69.fr
│ ├── I61Java.java
│ ├── Issue294.fr
│ ├── Issue257.fr
│ ├── Issue358.fr
│ ├── Issue323.fr
│ ├── Issue66.fr
│ ├── Issue68.fr
│ ├── Issue277a.fr
│ ├── Issue203.fr
│ ├── Issue296.fr
│ ├── Issue362.fr
│ ├── Issue258.fr
│ ├── Issue26.fr
│ ├── Underscore.fr
│ ├── Issue169.fr
│ ├── Issue290.fr
│ ├── Issue301.fr
│ ├── Issue357.fr
│ ├── Issue160.fr
│ ├── Issue61.fr
│ ├── Issue284.fr
│ ├── Issue345.fr
│ ├── Issue298.fr
│ ├── Issue152.fr
│ ├── Issue284a.fr
│ ├── Issue234.fr
│ ├── Issue355.fr
│ ├── TDNR.fr
│ ├── Issue126.fr
│ ├── Issue21.fr
│ ├── Issue103.fr
│ ├── Issue80.fr
│ ├── Issue297.fr
│ ├── Issue273.fr
│ ├── Issue271.fr
│ ├── Issue47.fr
│ ├── Issue67.fr
│ ├── Issue58.fr
│ ├── Issue20.fr
│ ├── Issue65.fr
│ ├── Issue336.fr
│ ├── Issue333.fr
│ ├── Issue55.fr
│ ├── Issue278.fr
│ └── Issue277.fr
├── hcm
│ ├── Layout.fr
│ ├── IdentifiersImport.fr
│ ├── NoModuleLayout.fr
│ ├── Lexical.fr
│ ├── NoModuleExplicit.fr
│ ├── Bool.fr
│ ├── Lambda.fr
│ └── Identifiers.fr
├── qc
│ ├── MonoidTest.fr
│ ├── Exit.fr
│ ├── Targets.fr
│ ├── PierresPrime.fr
│ ├── Regexes.fr
│ ├── Environment.fr
│ ├── Wrappers.fr
│ ├── Record.fr
│ └── JSON.fr
└── messages
│ └── Case1.fr
├── contrib
└── dgronau
│ ├── trans
│ ├── MonadTrans.fr
│ ├── MonadIO.fr
│ ├── TransTest.fr
│ ├── MaybeT.fr
│ └── EitherT.fr
│ ├── arrow
│ └── Category.fr
│ ├── Monadic.fr
│ ├── Alternative.fr
│ └── Floating.fr
├── examples
├── Welcome.fr
├── ForH.fr
├── ReverseStdin.fr
├── Euler7.fr
├── Postfix.fr
├── MoreTailCall.fr
├── TailCalls.fr
├── GoldenRatio.fr
├── Euler12.fr
├── RefExample.fr
├── SimpleIO.fr
├── Grep.fr
├── CommandLineClock.fr
├── Euler87.fr
├── HigherOrder.fr
├── UnicodeChars.fr
├── STM.fr
├── JHashMap.java
├── FunctionInstances.fr
├── Sort.fr
├── Euler94.fr
├── Evolution.fr
├── Diverge.fr
├── Euler92.fr
└── Brainfuck.fr
├── frege
├── data
│ ├── Either.fr
│ ├── Coproduct.fr
│ ├── wrapper
│ │ ├── Const.fr
│ │ ├── Endo.fr
│ │ ├── Dual.fr
│ │ ├── Ord.fr
│ │ ├── Boolean.fr
│ │ ├── ZipList.fr
│ │ ├── Num.fr
│ │ └── Identity.fr
│ ├── Product.fr
│ ├── Compose.fr
│ └── Maybe.fr
├── control
│ ├── monad
│ │ ├── trans
│ │ │ ├── MonadTrans.fr
│ │ │ ├── MonadIO.fr
│ │ │ ├── EitherT.fr
│ │ │ └── MaybeT.fr
│ │ └── Reader.fr
│ ├── First.fr
│ ├── Second.fr
│ ├── CombineIn.fr
│ ├── Tensor.fr
│ ├── Arrow.fr
│ ├── Category.fr
│ ├── arrow
│ │ └── Kleisli.fr
│ └── Semigroupoid.fr
├── Starter.fr
├── compiler
│ ├── types
│ │ ├── NSNames.fr
│ │ ├── ConstructorField.fr
│ │ ├── JNames.fr
│ │ ├── ImportDetails.fr
│ │ ├── Targets.fr
│ │ ├── QNames.fr
│ │ ├── Strictness.fr
│ │ └── SNames.fr
│ ├── enums
│ │ ├── CaseKind.fr
│ │ ├── SymState.fr
│ │ ├── Visibility.fr
│ │ ├── Literals.fr
│ │ ├── RFlag.fr
│ │ └── TokenID.fr
│ ├── instances
│ │ ├── PositionedSName.fr
│ │ └── NiceExprS.fr
│ ├── classes
│ │ └── QNameMatcher.fr
│ ├── grammar
│ │ └── Lexical.ebnf
│ ├── common
│ │ ├── Tuples.fr
│ │ └── Roman.fr
│ └── passes
│ │ └── Final.fr
├── StandardTools.fr
├── runtime
│ ├── NoMatch.java
│ ├── GuardFailed.java
│ ├── BlackHole.java
│ ├── Phantom.java
│ ├── CompilerSupport.java
│ ├── Regex9.java
│ ├── Undefined.java
│ ├── Value.java
│ ├── Ref.java
│ └── Javac.java
├── run8
│ ├── Utils.java
│ └── Lazy.java
├── java
│ ├── swing
│ │ └── GroupLayout.fr
│ ├── util
│ │ └── Zip.fr
│ └── lang
│ │ └── Reflect.fr
├── tools
│ └── fregedoc.html
├── system
│ ├── Exit.fr
│ └── Environment.fr
├── run7
│ └── Lazy.java
├── test
│ └── QuickCheckState.fr
└── StandardLibrary.fr
├── scripts
├── frege.bat
├── fregec.bat
├── mkmk.pl
├── mkversion.pl
├── savejava.pl
├── lein-deploy.sh
├── mkdist.pl
└── genFunc.pl
├── .travis.yml
├── .gitattributes
└── .gitignore
/doc/chapterio.tex:
--------------------------------------------------------------------------------
1 | \chapter{Input/Output}
2 |
3 | \todo{write it}
--------------------------------------------------------------------------------
/resources/Frege_logo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frege/frege/master/resources/Frege_logo.jpg
--------------------------------------------------------------------------------
/resources/Frege_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frege/frege/master/resources/Frege_logo.png
--------------------------------------------------------------------------------
/resources/Frege_logo_flat_colours.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frege/frege/master/resources/Frege_logo_flat_colours.jpg
--------------------------------------------------------------------------------
/resources/Frege_logo_flat_colours.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frege/frege/master/resources/Frege_logo_flat_colours.png
--------------------------------------------------------------------------------
/tests/nocomp/Issue348.fr:
--------------------------------------------------------------------------------
1 | module tests.nocomp.Issue348 where
2 |
3 | newtype Flip a b = Flip (b, a)
4 |
5 | instance Functor (Flip a) where
6 | fmap f (Flip (b, a)) = Flip ((f b), a)
7 |
--------------------------------------------------------------------------------
/tests/comp/Issue158.fr:
--------------------------------------------------------------------------------
1 | --- Wrong precedence for - in, for example, 1-2*3
2 | module tests.comp.Issue158 where
3 |
4 | main = do
5 | print "The result should be -5: "
6 | println (1-2*3)
7 |
--------------------------------------------------------------------------------
/tests/comp/Dezi.fr:
--------------------------------------------------------------------------------
1 | --- This is an undocumented module
2 | module tests.comp.Dezi where
3 |
4 |
5 | foo :: Decimal → Decimal
6 | foo z = z
7 |
8 | bar = foo 123.456e-111z
9 |
10 | main = println bar
--------------------------------------------------------------------------------
/tests/comp/Issue313.fr:
--------------------------------------------------------------------------------
1 | --- Code for 'https://github.com/Frege/frege/issues/313 Issue 313'
2 | module tests.comp.Issue313 where
3 |
4 | data Empty
5 |
6 | main = println "Yes, we can make a nullary data type."
--------------------------------------------------------------------------------
/contrib/dgronau/trans/MonadTrans.fr:
--------------------------------------------------------------------------------
1 | package frege.control.trans.MonadTrans where
2 |
3 | class MonadTrans t where
4 | --- Lift a computation from the argument monad to the constructed monad.
5 | lift :: Monad m => m a -> t m a
6 |
--------------------------------------------------------------------------------
/examples/Welcome.fr:
--------------------------------------------------------------------------------
1 | --- Test case for code generation with monadic code
2 | module examples.Welcome where
3 |
4 | main = do
5 | println "Hi there! What's your name?"
6 | name ← getLine
7 | println ("Welcome to Frege, " ++ name ++ "!")
8 |
--------------------------------------------------------------------------------
/tests/comp/Issue260.fr:
--------------------------------------------------------------------------------
1 | --- Minimal example for 'https://github.com/Frege/frege/issues/260 Issue 260'
2 | module tests.comp.Issue260 where
3 |
4 | data MyT a = MyT where
5 | phantomString = MyT :: MyT String
6 |
7 | main = println "Compiled, so okay"
--------------------------------------------------------------------------------
/tests/hcm/Layout.fr:
--------------------------------------------------------------------------------
1 | --- Differences in layout
2 | module tests.hcm.Layout where
3 |
4 | g = 3 where
5 |
6 | neg = [ n | p ← [0..], let n = -p, n > 2 ] -- no } inserted before ]
7 |
8 | main = do
9 | print x
10 | where x = 1
11 |
--------------------------------------------------------------------------------
/frege/data/Either.fr:
--------------------------------------------------------------------------------
1 | module Data.Either where
2 |
3 | fromLeft :: a -> Either a b -> a
4 | fromLeft _ (Left a) = a
5 | fromLeft a _ = a
6 |
7 | fromRight :: b -> Either a b -> b
8 | fromRight _ (Right b) = b
9 | fromRight b _ = b
10 |
--------------------------------------------------------------------------------
/scripts/frege.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | REM ***
3 | REM Frege runscript for Windows 7
4 | REM ***
5 |
6 | setLocal
7 |
8 | if "%FREGE_HOME%" == "" (set FREGE_HOME=build)
9 |
10 | java -cp "%FREGE_HOME%;build" %1 %2 %3 %4 %5 %6 %7 %8 %9
11 |
12 | endlocal
--------------------------------------------------------------------------------
/examples/ForH.fr:
--------------------------------------------------------------------------------
1 | module examples.ForH where
2 |
3 | -- import Data.List
4 |
5 | main _ = print $ take 10 pyth
6 | where
7 | pyth = [ (x, y, m*m+n*n) |
8 | m <- [2..], n <- [1..m-1],
9 | let { x = m*m-n*n; y = 2*m*n },
10 | ]
--------------------------------------------------------------------------------
/examples/ReverseStdin.fr:
--------------------------------------------------------------------------------
1 | --- Reverse the standard input
2 | module examples.ReverseStdin where
3 |
4 | main _ = loop [] >>= mapM_ stdout.write
5 |
6 | loop :: [Int] -> IO [Int]
7 | loop acc = do
8 | i <- stdin.read
9 | if i < 0 then return acc -- end of file
10 | else loop (i:acc)
11 |
--------------------------------------------------------------------------------
/frege/data/Coproduct.fr:
--------------------------------------------------------------------------------
1 | --- co-product
2 | package frege.data.Coproduct where
3 |
4 | data Coproduct (f ∷ * → *) (g ∷ * → *) a = Inl (f a) | Inr (g a)
5 |
6 | instance (Functor f, Functor g) => Functor (Coproduct f g) where
7 | fmap f (Inl fa) = Inl (fmap f fa)
8 | fmap f (Inr ga) = Inr (fmap f ga)
9 |
--------------------------------------------------------------------------------
/frege/control/monad/trans/MonadTrans.fr:
--------------------------------------------------------------------------------
1 | --- provide utility function 'lift' for 'Monad' transformers
2 | package frege.control.monad.trans.MonadTrans where
3 |
4 | class MonadTrans t where
5 | --- Lift a computation from the argument monad to the constructed monad.
6 | lift :: Monad m => m a -> t m a
7 |
--------------------------------------------------------------------------------
/scripts/fregec.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | REM ***
3 | REM Frege compile script for Windows 7
4 | REM ***
5 |
6 | setLocal
7 |
8 | if "%FREGE_HOME%" == "" (set FREGE_HOME=build)
9 |
10 | java -Xmx512m -Xss8m -cp "%FREGE_HOME%;build" frege.compiler.Main -d build -hints %1 %2 %3 %4 %5 %6 %7 %8 %9
11 |
12 | endlocal
--------------------------------------------------------------------------------
/scripts/mkmk.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use strict;
4 | use warnings;
5 |
6 | while (<>) {
7 | m/^JAVAC5/ and do { print "JAVAC5 = echo no java5 here\n"; next };
8 | s/pbyacc/byaccj/;
9 | # s/\bMakefile\b/frege.mk/;
10 | s/\.;build/.:build/;
11 | s/shadow;/shadow:/;
12 | print;
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/tests/comp/Issue332.fr:
--------------------------------------------------------------------------------
1 | --- Code for 'https://github.com/Frege/frege/issues/332 Issue 332'
2 | module tests.comp.Issue332 where
3 |
4 | data I332Java a = pure native java.util.List
5 |
6 | derive JavaType (I332Java a)
7 | derive ArrayElement (I332Java a)
8 |
9 | main = println "Yes, we can derive ArrayElement for generic Java type."
--------------------------------------------------------------------------------
/frege/Starter.fr:
--------------------------------------------------------------------------------
1 | --- dispatch between compiler and repl
2 | module frege.Starter where
3 |
4 | import Compiler.Main(main compiler)
5 | import Repl.FregeRepl(main repl)
6 |
7 |
8 | main :: [String] -> IO Bool
9 | main [] = repl >> pure true
10 | main ['^-?-?repl'] = repl >> pure true
11 | main other = compiler other
12 |
13 |
--------------------------------------------------------------------------------
/tests/comp/Issue69.fr:
--------------------------------------------------------------------------------
1 | --- Test case for Issue #69
2 | module tests.comp.Issue69 where
3 |
4 |
5 | class A a where
6 | aop :: a e -> e
7 |
8 | class B b where
9 | bop :: b e -> e
10 |
11 | class (A c, B c) => C c
12 |
13 | instance C [] where
14 | aop = head
15 | bop = head
16 |
17 | main = println (aop ["Yes"], bop ["Ok"])
--------------------------------------------------------------------------------
/frege/compiler/types/NSNames.fr:
--------------------------------------------------------------------------------
1 | --- Names of name spaces.
2 | module frege.compiler.types.NSNames where
3 |
4 |
5 | --- A namespace name, not to be confused with an ordinary 'String'
6 | newtype NSName = NSX { unNS :: String }
7 |
8 |
9 | derive Eq NSName
10 |
11 |
12 | derive Ord NSName
13 |
14 |
15 | derive Show NSName
16 |
17 |
18 |
--------------------------------------------------------------------------------
/tests/comp/I61Java.java:
--------------------------------------------------------------------------------
1 | package tests.comp;
2 |
3 | /**
4 | *
Test class to demonstrate that $ in method names and member names work.
5 | * @author ingo
6 | *
7 | */
8 | final public class I61Java {
9 | final public int mem$1;
10 | final public int $getMem1$() { return mem$1;}
11 | public I61Java(int arg) { mem$1 = arg; }
12 | }
13 |
--------------------------------------------------------------------------------
/tests/comp/Issue294.fr:
--------------------------------------------------------------------------------
1 | --- Issue 294, code generation aborts with "can't adapt"
2 | --- when undefined is assigned a constrained type
3 | module tests.comp.Issue294 where
4 |
5 | schlecht :: Eq a => a -> a
6 | schlecht = undefined
7 |
8 | -- the following is fine instead
9 | -- schlecht x = undefined x
10 |
11 |
12 |
13 | main = println true
--------------------------------------------------------------------------------
/tests/comp/Issue257.fr:
--------------------------------------------------------------------------------
1 | --- See 'https://github.com/Frege/frege/issues/257 Issue 257'
2 | module tests.comp.Issue257 where
3 |
4 | type Lens s t a b = forall f . Functor f => (a -> f b) -> (s -> f s)
5 |
6 | foo :: Lens String () Bool Char
7 | foo x i = fmap (const i) (x true)
8 |
9 | bar = const (Just 'c')
10 |
11 | main = println (foo bar "Okay")
12 |
--------------------------------------------------------------------------------
/tests/comp/Issue358.fr:
--------------------------------------------------------------------------------
1 | {--
2 | if there are ambiguities when resolving an overloaded function, choose the one
3 | with the smalles arity that still type checks.
4 | -}
5 | module tests.comp.Issue358 where
6 |
7 | main :: IO Bool
8 | main = do
9 | println ("%X".format 0xedda)
10 | println (map "%3d".format [1..10])
11 | pure true
12 |
--------------------------------------------------------------------------------
/frege/compiler/enums/CaseKind.fr:
--------------------------------------------------------------------------------
1 | --- "Kind" of a case
2 | module frege.compiler.enums.CaseKind where
3 |
4 | {--
5 | case kind
6 | -}
7 | data CKind =
8 | CNormal --- normal case
9 | | CWhen --- case that falls through
10 | | CNoWarn --- compiler generated, do not emit warnings
11 |
12 | derive Eq CKind
13 | derive Enum CKind
--------------------------------------------------------------------------------
/tests/nocomp/Issue286.fr:
--------------------------------------------------------------------------------
1 | --- 'https://github.com/Frege/frege/issues/286 Issue 286'
2 | --- Refuse to make native types instances of higher kinded classes
3 | module tests.nocomp.Issue286 where
4 |
5 | import frege.java.Util(List)
6 |
7 | instance Functor List where fmap = undefined
8 |
9 | newtype JList a = J (List a)
10 |
11 | instance Functor JList where fmap = undefined
--------------------------------------------------------------------------------
/frege/compiler/enums/SymState.fr:
--------------------------------------------------------------------------------
1 | --- Symbol state
2 | module frege.compiler.enums.SymState where
3 |
4 | {--
5 | symbol state
6 | -}
7 | data SymState = Unchecked | Typechecking | Recursive | Typechecked | StrictChecked
8 |
9 |
10 | derive Eq SymState
11 |
12 |
13 | derive Ord SymState
14 |
15 |
16 | derive Show SymState
17 |
18 |
19 | derive Enum SymState
20 |
21 |
22 |
--------------------------------------------------------------------------------
/tests/hcm/IdentifiersImport.fr:
--------------------------------------------------------------------------------
1 | --- Support for identifiers starting with an underscore
2 | module tests.hcm.IdentifiersImport where
3 |
4 | import tests.hcm.Identifiers (_f, final, _final, ®, a'a', a''a'')
5 |
6 | main :: IO ()
7 | main = do
8 | putStrLn final
9 | putStrLn _final
10 | putStrLn $ _f True
11 | putStrLn $ 1 ® 2
12 | putStrLn $ (a'a' . a''a'') "A'p'o's't'r'o'p'h'e's"
13 |
--------------------------------------------------------------------------------
/tests/nocomp/Issue125.fr:
--------------------------------------------------------------------------------
1 | {--
2 | Example code for 'https://github.com/Frege/frege/issues/125 issue 125'
3 |
4 | The attempt to unify mutable native types with their supertypes must fail
5 | when the supertype is not also mutable native.
6 | -}
7 | module tests.nocomp.Issue125 where
8 |
9 |
10 | pure native toString :: Object -> String
11 |
12 | wrong = toString stdin
13 |
14 |
--------------------------------------------------------------------------------
/frege/control/monad/Reader.fr:
--------------------------------------------------------------------------------
1 | --- 'Reader' monad and monad transformer, based on 'Kleisli'
2 | package frege.control.monad.Reader where
3 |
4 | import frege.Prelude hiding (Reader)
5 | import frege.control.arrow.Kleisli
6 | import frege.data.wrapper.Identity
7 |
8 | type Reader a b = Kleisli Identity a b
9 |
10 | type ReaderT m a b = Kleisli m a b
11 |
12 | ask :: Monad m => ReaderT m e e
13 | ask = id
--------------------------------------------------------------------------------
/tests/comp/Issue323.fr:
--------------------------------------------------------------------------------
1 | --- This is an undocumented module
2 | module tests.comp.Issue323 where
3 |
4 | import Control.Arrow
5 |
6 | -- "type class"
7 | class Arrow a => ArrowApply a where
8 | app :: a (a b c, b) c
9 |
10 | -- "instance" for (->)
11 | instance ArrowApply (->) where
12 | app :: (b -> c, b) -> c
13 | app (f, b) = arr f b
14 |
15 | -- use it
16 | main = println (app ((1+), 3))
--------------------------------------------------------------------------------
/tests/comp/Issue66.fr:
--------------------------------------------------------------------------------
1 | --- see 'https://github.com/Frege/frege/issues/66 issue 66'
2 | --- Results in a javac error, because B.foo is lazier than A.foo
3 | module tests.comp.Issue66 where
4 |
5 | class A a where
6 | foo :: Maybe a -> Int
7 |
8 | class A b => B b where
9 | foo = maybe 0 (const 42)
10 |
11 | instance B String
12 |
13 | main = println (foo (Just "Okay")) >> println (foo (Nothing:: Maybe String))
--------------------------------------------------------------------------------
/tests/comp/Issue68.fr:
--------------------------------------------------------------------------------
1 | --- Test case for issue #68
2 | package tests.comp.Issue68
3 | -- inline(§, k, s, i, b)
4 | where
5 |
6 |
7 |
8 | data Y f = Y (f (Y f))
9 |
10 | datum = Y (Left "Yes")
11 | --- This should compile without sending the code generation in an endless loop
12 | unR (Y (Left x) ) = Just x
13 | unR (Y (Right x)) = Nothing
14 | --
15 |
16 | main = do println $ unR datum
17 |
--------------------------------------------------------------------------------
/frege/StandardTools.fr:
--------------------------------------------------------------------------------
1 | --- The purpose of this package is to get all tools compiled
2 |
3 | module StandardTools where
4 |
5 | -- we use public imports to avoid "unused import" hints
6 |
7 | import frege.tools.Doc public()
8 | import frege.tools.YYgen public()
9 | import frege.tools.Quick public()
10 | import frege.ide.Utilities public()
11 | import frege.tools.Splitter public()
12 | import frege.tools.MakeDocIndex public()
13 |
--------------------------------------------------------------------------------
/tests/comp/Issue277a.fr:
--------------------------------------------------------------------------------
1 | --- This is an undocumented module
2 | module tests.comp.Issue277a where
3 |
4 | class Bar c
5 |
6 | -- this works
7 | -- foo :: (forall b. Bar b => b -> b) -> (forall a. a -> a)
8 | -- this crashed in code generation
9 | foo :: (forall a. Bar a => a -> a) -> (forall a.a -> a)
10 | foo f = foo f
11 |
12 | gid :: (∀ a. Bar a => a -> a) -> (∀ a. Bar a => a -> a)
13 | gid f = f
14 |
15 | main = println "Compiled, ok"
--------------------------------------------------------------------------------
/frege/control/First.fr:
--------------------------------------------------------------------------------
1 | --- type class 'First' with 'first' operation
2 | package frege.control.First where
3 |
4 | import frege.control.Tensor
5 |
6 | class (Tensor f) => First f where
7 | {--
8 | Send the first component of the input through the argument
9 | tensor, and copy the rest unchanged to the output.
10 | -}
11 | first :: f a b -> f (a, c) (b, c)
12 |
13 | instance First (->) where
14 | first f = \(a, c) -> (f a, c)
--------------------------------------------------------------------------------
/tests/comp/Issue203.fr:
--------------------------------------------------------------------------------
1 | --- Check resolution for 'https://github.com/Frege/frege/issues/203 Issue 203'
2 | module tests.comp.Issue203 where
3 |
4 | data R a = R { v :: a, f :: forall b.a -> [b] -> [b] }
5 |
6 | x = R 42 drop
7 |
8 | y = x.{f <- \f i -> drop i . f i}
9 |
10 | z = x.{f = take}
11 |
12 | main = do
13 | println (x.f 10 (replicate 13 "3×Ok"))
14 | println (y.f 10 (replicate 23 "3×Ok"))
15 | println (z.f 3 (repeat "3×Ok"))
--------------------------------------------------------------------------------
/frege/control/Second.fr:
--------------------------------------------------------------------------------
1 | --- type class 'Second' with 'second' operation
2 | package frege.control.Second where
3 |
4 | import frege.control.Tensor
5 |
6 | class (Tensor f) => Second f where
7 | {--
8 | Send the second component of the input through the argument
9 | tensor, and copy the rest unchanged to the output.
10 | -}
11 | second :: f c d -> f (a, c) (a, d)
12 |
13 | instance Second (->) where
14 | second f = \(a, c) -> (a, f c)
--------------------------------------------------------------------------------
/tests/qc/MonoidTest.fr:
--------------------------------------------------------------------------------
1 | module tests.qc.MonoidTest where
2 |
3 | import Data.NonEmpty (nonEmpty)
4 | import Data.Monoid (Monoid, sconcat, mconcat, <>)
5 | import Test.QuickCheck
6 |
7 | checkSemigroupConcat :: (Monoid a, Eq a) => a -> [a] -> Bool
8 | checkSemigroupConcat head tail =
9 | head <> mconcat tail == sconcat (nonEmpty head tail)
10 |
11 | p_semigroupConcatStrings =
12 | property (checkSemigroupConcat :: String -> [String] -> Bool)
13 |
--------------------------------------------------------------------------------
/frege/data/wrapper/Const.fr:
--------------------------------------------------------------------------------
1 | --- type level 'const'
2 | --- 'Const' is a way to use some arbitrary type as an applicative 'Functor'
3 | package frege.data.wrapper.Const where
4 |
5 | import Data.Monoid
6 |
7 | data Const a b = Const { get :: a }
8 |
9 | instance Functor (Const m) where
10 | fmap _ (Const v) = Const v
11 |
12 | instance Monoid m => Applicative (Const m) where
13 | pure _ = Const mempty
14 | Const f <*> Const v = Const (f `mappend` v)
--------------------------------------------------------------------------------
/tests/hcm/NoModuleLayout.fr:
--------------------------------------------------------------------------------
1 | {--
2 | From the Haskell 2010 report:
3 |
4 | An abbreviated form of module, consisting only of the module body, is permitted.
5 | If this is used, the header is assumed to be
6 |
7 | > module Main where’
8 |
9 | If the first lexeme in the abbreviated module is not a @{@,
10 | then the layout rule applies for the top level of the module.
11 | -}
12 | main = println (hello ++ " from Main")
13 |
14 | hello = "Greetings"
15 |
--------------------------------------------------------------------------------
/examples/Euler7.fr:
--------------------------------------------------------------------------------
1 | --- print prime numbers
2 |
3 | package examples.Euler7 where
4 |
5 | import examples.EulerLib
6 |
7 |
8 | --- give some integers > 0
9 | main :: [String] -> IO ()
10 | main = println
11 | • map (either (const (-1n)) ((primes !!) • (subtract 1))) -- get corresponding prime
12 | • filter (either (const false) (>0)) -- make sure its right and > 0
13 | • map String.int -- [String] -> [Exception Int]
14 |
--------------------------------------------------------------------------------
/frege/data/Product.fr:
--------------------------------------------------------------------------------
1 | --- A pair of two applicative functors, both applied to the same type
2 | package frege.data.Product where
3 |
4 | import frege.Prelude hiding(product)
5 |
6 | data Product f g a = Prod (f a) (g a)
7 |
8 | instance (Functor f, Functor g) => Functor (Product f g) where
9 | fmap f (Prod fa ga) = Prod (fmap f fa) (fmap f ga)
10 |
11 | --- view a tuple as 'Product'
12 | product = uncurry Prod
13 |
14 | --- make a tuple from a 'Product'
15 | unproduct (Prod a b) = (a,b)
--------------------------------------------------------------------------------
/tests/comp/Issue296.fr:
--------------------------------------------------------------------------------
1 | module tests.comp.Issue296 where
2 |
3 | data RType = DeadEnd | WinningCycle | LosingCycle
4 |
5 | derive Show RType
6 |
7 | exampleGood :: (RType, ())
8 | exampleGood = (l w', ()) where
9 | l true = WinningCycle
10 | l false = LosingCycle
11 | w' = if true then false else true
12 |
13 | exampleBad :: (RType, ())
14 | exampleBad = (if w' then LosingCycle else WinningCycle, ()) where
15 | w' = if true then false else true
16 |
17 | main = println exampleBad
--------------------------------------------------------------------------------
/frege/control/CombineIn.fr:
--------------------------------------------------------------------------------
1 | --- type class 'CombineIn', which provides the '&&&' operator
2 | package frege.control.CombineIn where
3 |
4 | import frege.control.Semigroupoid (Semigroupoid())
5 |
6 | infixr 3 `&&&`
7 |
8 | class (Semigroupoid f) => CombineIn f where
9 | {--
10 | Send the input to both argument semigroupoids and combine
11 | their output.
12 | -}
13 | (&&&) :: f a b -> f a c -> f a (b, c)
14 |
15 | instance CombineIn (->) where
16 | f &&& g = \a -> (f a, g a)
--------------------------------------------------------------------------------
/tests/nocomp/Issue293.fr:
--------------------------------------------------------------------------------
1 | module tests.nocomp.Issue293 where
2 |
3 |
4 | data Log t = LogA { message :: String,
5 | integer :: Maybe t } |
6 | LogB { message :: String,
7 | boolean :: Bool }
8 | newtype Logger t a = Logger { runLog :: (a, [Log t]) }
9 | instance Monad (Logger t) where
10 | pure a = Logger (a, [])
11 | (Logger (a, xs)) >>= f = Logger (a', xs ++ xs')
12 | where (a', xs') = Logger.runLog $ f a
13 | tell s = Logger ((), s)
14 |
--------------------------------------------------------------------------------
/tests/comp/Issue362.fr:
--------------------------------------------------------------------------------
1 | --- crash in typechecker
2 | --- "bad types in unification"
3 | module tests.comp.Issue362 where
4 |
5 | pure native getN getName :: Class(extends Object) -> String
6 |
7 | derive ArrayElement (Class (extends Object))
8 | instance Show (Class (extends Object)) where
9 | show c = getN c
10 |
11 | list = [Int.javaClass :: Class(extends Object)]
12 |
13 | array = arrayFromList list
14 |
15 | c = array.[0]
16 | s = show c
17 | d = getN c
18 |
19 | main = println c >> println "Ok"
--------------------------------------------------------------------------------
/tests/hcm/Lexical.fr:
--------------------------------------------------------------------------------
1 | --- Show lexical incompatibilities between Frege and Haskell 2010
2 | module tests.hcm.Lexical where
3 |
4 | -- variable names
5 |
6 | æ = 4
7 |
8 | -- constructor operators
9 |
10 | data Complex = Double :+ Double
11 |
12 |
13 | -- octal integer literals
14 |
15 | twentysix = 0o32
16 |
17 | dangerous = 032 -- 32 in Haskell, 26 in Frege
18 |
19 | -- multi line strings
20 |
21 | string_with_gap = "abc/ /def" -- "abcdef"
22 | multi_line = "abc/
23 | /def"
24 |
25 |
--------------------------------------------------------------------------------
/tests/nocomp/Issue102.fr:
--------------------------------------------------------------------------------
1 | --- Test for 'https://github.com/Frege/frege/issues/102 issue 102'
2 | module tests.nocomp.Issue102 where
3 |
4 | --- the following data definition is forbidden
5 | --- compiler must complain about non-introduced type variable "int"
6 |
7 | data Wrong = Falsch int
8 |
9 | --- otherwise, the following would be possible:
10 |
11 | main = println (foo (Falsch 42)) -- ClassCastException Integer -> String
12 | where
13 | foo :: Wrong -> String
14 | foo (Falsch s) = s
15 |
--------------------------------------------------------------------------------
/examples/Postfix.fr:
--------------------------------------------------------------------------------
1 | --
2 | --- For Sean
3 | --- Show that postfix operators do indeed work.
4 | --
5 | module examples.Postfix where
6 |
7 | import Test.QuickCheck as Q
8 |
9 | infix 1 `³` `²`
10 |
11 | --- cube of a number
12 | (x³) = x ^ 3
13 |
14 | --- square of a number
15 | (²) = (^2)
16 |
17 | prop23 = property (\(n :: Integer) -> (n³) == n*(n²))
18 |
19 | main = do
20 | print "venti sette "
21 | println (3³)
22 | print "some cubes "
23 | println (map (³) [1..10])
24 | Q.quickCheck prop23
25 |
--------------------------------------------------------------------------------
/frege/compiler/types/ConstructorField.fr:
--------------------------------------------------------------------------------
1 | --- The type 'ConField' models a field in a data constructor.
2 | module frege.compiler.types.ConstructorField where
3 | -- generated by Splitter
4 | import frege.compiler.types.Positions
5 | import frege.compiler.enums.Visibility
6 | import frege.compiler.types.Types
7 |
8 | --- a constructor field
9 | data ConField s = !Field { pos :: Position, name, doc :: Maybe String,
10 | vis :: Visibility, strict :: Bool, typ :: SigmaT s }
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 |
3 | jdk:
4 | - openjdk11
5 |
6 | # addons:
7 | # apt:
8 | # packages:
9 | # - oracle-java9-installer
10 |
11 | before_install:
12 | - sudo apt-get update -qq
13 | - sudo apt-get install -y byacc
14 |
15 | before_script:
16 | - mkdir -p build dist doc
17 | # Get the latest fregec.jar to compile the compiler
18 | - curl -L -o fregec.jar https://github.com/Frege/frege/releases/download/3.25alpha/frege3.25.84.jar
19 |
20 | script:
21 | - make compiler1
22 |
--------------------------------------------------------------------------------
/frege/control/Tensor.fr:
--------------------------------------------------------------------------------
1 | --- The 'Tensor' type class with '***' operation.
2 | package frege.control.Tensor where
3 |
4 | import frege.control.Semigroupoid (Semigroupoid())
5 |
6 | infixr 3 `***`
7 |
8 | class (Semigroupoid f) => Tensor f where
9 | {--
10 | Split the input between the two argument semigroupoids and combine
11 | their output. Note that this is in general not a functor.
12 | -}
13 | (***) :: f a b -> f c d -> f (a, c) (b, d)
14 |
15 | instance Tensor (->) where
16 | f *** g = \(a, c) -> (f a, g c)
--------------------------------------------------------------------------------
/scripts/mkversion.pl:
--------------------------------------------------------------------------------
1 | #!perl -w
2 |
3 |
4 | use strict;
5 | use warnings;
6 |
7 |
8 | my $version = qx{git describe --long};
9 | my $commit = qx{git log -n 1};
10 | chomp $version;
11 | chomp $commit;
12 | $version =~ s/-(\d+)-.*$/.$1/;
13 | $commit =~ s/\n/\\n/g;
14 | $commit =~ s/\r//g;
15 | $commit =~ s/"/\\"/g;
16 | $commit =~ s/<[^>]*>//;
17 | print <[b]) -> (g xs, g ys) }
10 |
11 | -- This used to compile and give a type error at runtime. No more!
12 | typefailure = worksnot (map Double.sqrt) [true, false] ['a', 'b']
13 |
--------------------------------------------------------------------------------
/tests/hcm/NoModuleExplicit.fr:
--------------------------------------------------------------------------------
1 | {--
2 | From the Haskell 2010 report:
3 |
4 | An abbreviated form of module, consisting only of the module body, is permitted.
5 | If this is used, the header is assumed to be
6 |
7 | > module Main where’
8 |
9 | If the first lexeme in the abbreviated module is not a @{@,
10 | then the layout rule applies for the top level of the module.
11 | -}
12 |
13 | {
14 | main = println ("Explicit " ++ greetings ++ " from Main.");
15 |
16 | greetings = "greetings" }
17 |
18 |
--------------------------------------------------------------------------------
/frege/runtime/NoMatch.java:
--------------------------------------------------------------------------------
1 | package frege.runtime;
2 |
3 |
4 |
5 | /**
6 | *
Exception thrown when all matches of a case or lambda fail.
7 | *
8 | * throw new NoMatch(...) is
9 | * inserted by the compiler at appropriate places.
10 | *
11 | */
12 |
13 |
14 | public class NoMatch extends Undefined {
15 | static final long serialVersionUID = 1L;
16 |
17 | public NoMatch(String qname, int line, Object x) {
18 | super(qname + " at line " + line + " no match for value " + x);
19 | }
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/tests/comp/Issue258.fr:
--------------------------------------------------------------------------------
1 | --- Compiler should fail on type Stream, since (Cons a (Cons a)) is a kind error
2 | --- Compiler complains only when 'infinite' is uncommented.
3 | --- (Should this be in nocomp?)
4 |
5 | module tests.comp.Issue258 where
6 |
7 |
8 | type Omega s = s s
9 |
10 | data Cons a b = Cons a b
11 |
12 | type Stream a = Omega (Cons a)
13 |
14 |
15 | --infinite :: a -> Stream a
16 | --infinite x = undefined
17 |
18 | data Const a b = Const { getConst :: a }
19 |
20 | main :: IO Bool
21 | main = println "This should not compile." >> pure true
--------------------------------------------------------------------------------
/tests/comp/Issue26.fr:
--------------------------------------------------------------------------------
1 | --- implemented negative patterns
2 | module tests.comp.Issue26 where
3 |
4 | -- next gives message: "only numeric patterns may be negated"
5 | --wrong (-"bar") = "xx"
6 |
7 | foo (-42n) = "Okay"
8 | foo _ = "Not OK"
9 |
10 | bar (-42) = "Okay"
11 | bar _ = "Not OK"
12 |
13 | baz (-42.0) = "Okay"
14 | baz _ = "Not OK"
15 |
16 | main ∷ IO Bool
17 | main = do
18 | println (foo (-42n))
19 | println (bar (-42))
20 | println (baz (-42.0))
21 | pure (foo (-42n) == "Okay" && bar (-42) == "Okay" && baz (-42.0) == "Okay")
22 |
--------------------------------------------------------------------------------
/frege/run8/Utils.java:
--------------------------------------------------------------------------------
1 | package frege.run8;
2 |
3 | import java.util.function.*;
4 | /**
5 | * Helper functions to convert between Java8 function types and Frege functions.
6 | * @author ingo
7 | *
8 | */
9 | public abstract class Utils {
10 | /**
Make a {@link BiFunction} from a Frege function that takes 2 arguments
*/
11 | public static BiFunction bifunction(Func.U> f) {
12 | return (T a, U b) -> f
13 | .apply(Thunk.lazy(a))
14 | .call()
15 | .apply(Thunk.lazy(b))
16 | .call();
17 | }
18 |
19 | }
--------------------------------------------------------------------------------
/tests/comp/Underscore.fr:
--------------------------------------------------------------------------------
1 | --- Test changed behavior of @_.foo bar@ expressions
2 | module tests.comp.Underscore where
3 |
4 |
5 | main = do
6 | println "filter (not . _.startsWith \"foobar\") [\"foo\", \"bar\", \"foobarbaz\"]"
7 | print "Used to be: "
8 | println $ filter (not . "foobar".startsWith) strings
9 | print "Should now be: "
10 | println $ filter (not . (String.`startsWith` "foobar")) strings
11 | println $ filter (not . _.startsWith "foobar") strings
12 | where
13 | strings = ["foo", "bar", "foobarbaz"]
--------------------------------------------------------------------------------
/tests/hcm/Bool.fr:
--------------------------------------------------------------------------------
1 | --- This is an undocumented module
2 | module tests.hcm.Bool where
3 |
4 | --- can be used qualified or unqualified
5 | --- in patterns as well as expressions
6 | nicht True = Prelude.HaskellBool.False
7 | nicht HaskellBool.False = True
8 |
9 | alle = [False ..]
10 |
11 | {--
12 | interestingly, we have now a function that
13 | can detect whether we run under Frege
14 | -}
15 | isThisFrege = show True == "true"
16 |
17 | import frege.prelude.PreludeBase (True Wahr, False Falsch)
18 |
19 | youCanTrickMe = Wahr == Falsch -- no, you can't
--------------------------------------------------------------------------------
/tests/comp/Issue169.fr:
--------------------------------------------------------------------------------
1 | --- When top level definitions are not lazy enough, this program may hang.
2 | module tests.comp.Issue169 where
3 |
4 | import frege.lib.ForkJoin(mapP)
5 |
6 | doSomething :: Int → Int
7 | doSomething x = x * x
8 |
9 | -- sumOther = sum (map doSomething [1,2,3])
10 | sumNumbers = sum (mapP doSomething [9, 10, 3, 4])
11 |
12 |
13 | main args = do
14 | -- let
15 | -- sumSquares = sum ( mapP doSomething [9, 10, 3, 4, 7, 3, 49, 10, 3, 4, 7, 3, 49, 10, 3, 4, 7, 3, 4, 10] )
16 | -- println sumOther
17 | println (sumNumbers)
18 |
--------------------------------------------------------------------------------
/tests/hcm/Lambda.fr:
--------------------------------------------------------------------------------
1 | --- Haskell Lambda syntax
2 |
3 | module tests.hcm.Lambda where
4 |
5 | f = \a b -> (b,a)
6 |
7 | -- the following is now a syntax error
8 | -- Frege: unexpected operator : while trying to parse lambda patterns
9 | -- Haskell: parse error on input `:'
10 | -- s = \x:xs -> xs
11 |
12 | -- and this is also an error
13 | -- Frege: constructor Maybe.Just demands 1 arguments, but you gave 0
14 | -- Haskell: Constructor `Just' should have 1 argument, but has been given none
15 | -- j = \Just x -> x
16 |
17 | main = println (f true 'a')
18 |
--------------------------------------------------------------------------------
/tests/comp/Issue290.fr:
--------------------------------------------------------------------------------
1 | --- see also 'https://github.com/Frege/frege/issues/290 Issue 290'
2 | --- support strictness annotations in unnamed constructor fields
3 | module tests.comp.Issue290 where
4 |
5 | data Issue290 = Issue290 !String ?Int
6 |
7 | unfein = Issue290 "Okay" (42 `quot` 0)
8 |
9 | main :: IO Bool
10 | main = case unfein of
11 | -- the following line would first print "Okay" and only then die from evaluating 42/0
12 | -- Issue290 s x → println s >> pure (x > 7)
13 | -- the following line does not evaluate the int field
14 | Issue290 s x → println s >> pure true
--------------------------------------------------------------------------------
/tests/qc/Exit.fr:
--------------------------------------------------------------------------------
1 | --- Test properties of the 'Exit' module
2 | module tests.qc.Exit where
3 |
4 | import System.Exit as E
5 | import Test.QuickCheck
6 |
7 | o_ExitCodeSuccessEqOrd = once ( ExitSuccess == ExitSuccess &&
8 | not ( ExitSuccess < ExitSuccess ) )
9 |
10 | exitCodes :: Gen Int
11 | exitCodes = choose (1,99)
12 |
13 | p_ExitCodeFailureEqOrd = forAll exitCodes (\x ->
14 | ExitFailure x == ExitFailure x &&
15 | ExitFailure x < ExitFailure (x + 1))
16 |
17 | o_ExitCodeSuccessFailure = once ( ExitSuccess /= ExitFailure 1 &&
18 | ExitSuccess < ExitFailure 1 )
19 |
--------------------------------------------------------------------------------
/frege/data/wrapper/Endo.fr:
--------------------------------------------------------------------------------
1 | --- 'Monoid' instance for endofunctions
2 | module frege.data.wrapper.Endo where
3 |
4 | import Data.Monoid
5 |
6 |
7 | --- The monoid of endomorphisms under composition.
8 | newtype Endo a = Endo { unwrap :: a -> a }
9 | appEndo = Endo.unwrap
10 |
11 | {--
12 | The 'Monoid' instance for 'Endo' has functions as objects,
13 | uses '•' as operation and the identity is 'id'. -}
14 | instance Monoid (Endo a) where
15 | --- > Endo f <> Endo g = Endo (f . g)
16 | Endo f `mappend` Endo g = Endo (f • g)
17 | --- > Endo id
18 | mempty = Endo id
19 |
--------------------------------------------------------------------------------
/tests/comp/Issue301.fr:
--------------------------------------------------------------------------------
1 | --- Incompatibility of function 'words' with Haskell
2 | --- see 'https://github.com/Frege/frege/issues/301 issue 301'
3 | module tests.comp.Issue301 where
4 |
5 | main = do
6 | println ("Expected: " ++ show expected)
7 | println ("Got: " ++ show result)
8 | println ("Apparently, the words function is "
9 | ++ (if result == expected then "fully" else "not")
10 | ++ " compatible with Haskell2010.")
11 | where
12 | result = words " one two three"
13 | expected = ["one", "two", "three"]
14 |
--------------------------------------------------------------------------------
/tests/comp/Issue357.fr:
--------------------------------------------------------------------------------
1 | {--
2 | As outlined in 'https://github.com/Frege/frege/issues/357 #357',
3 | the compiler decides that 'myFoldM' should be strict, despite the tail call
4 | 'Maybe.>>=' returns lazy. This is unfortunate, because the recursion happens
5 | on the stack, instead through a Thunk returned by >>=
6 | -}
7 | module tests.comp.Issue357 where
8 |
9 | myFoldM :: (b -> a -> Maybe b) -> b -> [a] -> Maybe b
10 | myFoldM f z (x:xs) = f z x >>= \acc -> myFoldM f acc xs
11 | myFoldM _ z [] = pure z
12 |
13 | main = println $ myFoldM (\r _ -> Just $! succ r) 0 [1..5000]
14 |
--------------------------------------------------------------------------------
/frege/runtime/GuardFailed.java:
--------------------------------------------------------------------------------
1 | package frege.runtime;
2 |
3 | /**
4 | *
Exception thrown when the guard of the last case alternative fails.
5 | *
throw new GuardFailed(...) is inserted by the compiler
6 | * at appropriate places and helps identify the
7 | * source line number of the guard.
8 | * @author ingo
9 | *
10 | */
11 | public class GuardFailed extends Undefined {
12 |
13 | static final long serialVersionUID = 1L;
14 |
15 | public GuardFailed(String qname, int line) {
16 | super(qname + " at line " + line + ": guard failed.");
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/examples/MoreTailCall.fr:
--------------------------------------------------------------------------------
1 | -- module examples.MoreTailCall where
2 |
3 | import Data.List (isPrefixOf)
4 |
5 | match :: Int -> [Int] -> [Int] -> Bool
6 | match n list1 list2 = match1 (take n (cycle [1,1,2,2,2])) where
7 |
8 | match1 [] = True
9 | match1 list | list1 `isPrefixOf` list = match2 (drop (length list1) list)
10 | match1 _ = False
11 |
12 | match2 [] = False
13 | match2 list | list2 `isPrefixOf` list = match1 (drop (length list2) list)
14 | match2 _ = False
15 |
16 | --- should print true if argument is divisible by 5
17 |
18 | main = putStrLn $ show $ match 12345670 [1,1] [2,2,2]
--------------------------------------------------------------------------------
/tests/nocomp/Issue47a.fr:
--------------------------------------------------------------------------------
1 | --- Example code for 'https://github.com/Frege/frege/issues/47 Issue 47'
2 | module tests.nocomp.Issue47a where
3 |
4 | -- originally, the forall type didn't propagate to the top.
5 | -- This should be fixed by now.
6 | with (f::forall 𝖚.[𝖚]->[𝖚]) xs ys = (f xs, f ys)
7 |
8 | -- the following must not compile, and give messages:
9 | -- * type error in expression map (+ 1n) type is [Integer] used as [𝖚]
10 | -- * type `Integer` is not as polymorphic as suggested
11 | -- in the annotation where just `𝖚` is announced.
12 | wrong1 = with (map (1n+)) ['2', '3'] [true, false]
13 |
14 |
--------------------------------------------------------------------------------
/tests/comp/Issue160.fr:
--------------------------------------------------------------------------------
1 | --- 'https://github.com/Frege/frege/issues/160 Illegal Java code for polymorphic constrained non-function field'
2 | module tests.comp.Issue160 where
3 |
4 | {--
5 | Wrong code for the change function is generated,
6 | which tries to apply a context to an Object (i.e. the 'Showable.wrong' member)
7 | -}
8 | -- data Showable = S { flag :: Bool, wrong :: (forall a. Show a => a) }
9 |
10 | --- Even more reduced
11 | data S2 = S2 Bool (forall a.Show a => a)
12 |
13 | trythis :: S2 -> String
14 | trythis v = case v of
15 | S2 _ x -> x
16 |
17 | main = println "Ok" -- can not construct an S2
18 |
--------------------------------------------------------------------------------
/tests/comp/Issue61.fr:
--------------------------------------------------------------------------------
1 | --- 'https://github.com/Frege/frege/issues/61 Issue#61'
2 | {--
3 | Compiler does not recognize instance methods and members
4 | that have a @$@ sign in their name.
5 | -}
6 | module tests.comp.Issue61 where
7 |
8 |
9 | data Native = pure native tests.comp.I61Java where
10 | pure native new :: Int -> Native
11 | pure native member ".mem$1" :: Native -> Int
12 | pure native method "$getMem1$" :: Native -> Int
13 |
14 | main _ = do
15 | let nat = Native.new 42
16 | print "Member mem$1 is "
17 | println nat.member
18 | print "Method $getMem1$ returns "
19 | println nat.method
--------------------------------------------------------------------------------
/tests/qc/Targets.fr:
--------------------------------------------------------------------------------
1 | --- This is an undocumented module
2 | module tests.qc.Targets where
3 |
4 | import Compiler.types.Targets as T
5 | import Test.QuickCheck public
6 |
7 | {-- For a valid target string, the result of showing a decoded
8 | target should be the original string. -}
9 | p_sts ∷ Property
10 | p_sts = forAll (elements ["0.1", "x.y", "1.7",
11 | "-5.3f", "1.8.23", "9", "12345.67890" ])
12 | stringit
13 | where
14 | stringit ∷ String → Bool
15 | stringit s = case Target.decode s of
16 | Just t → s == show t
17 | Nothing → true
18 |
19 |
--------------------------------------------------------------------------------
/frege/control/Arrow.fr:
--------------------------------------------------------------------------------
1 | --- type class for 'Arrow's
2 | package frege.control.Arrow where
3 |
4 | import frege.Prelude
5 |
6 | import frege.control.Category (Category())
7 | import frege.control.First
8 | import frege.control.Second
9 | import frege.control.CombineIn
10 |
11 | {--
12 | Basic arrow definitions, based on
13 | Generalising Monads to Arrows, by John Hughes,
14 | Science of Computer Programming, pp67-111, May 2000.
15 | -}
16 | class (Category a, First a, Second a, CombineIn a) => Arrow a where
17 | --- Lift a function to an arrow.
18 | arr :: (b -> c) -> a b c
19 |
20 | instance Arrow (->) where
21 | arr = id
22 |
--------------------------------------------------------------------------------
/frege/data/Compose.fr:
--------------------------------------------------------------------------------
1 | {--
2 | Composition of two applicative functors _f_ and _g_
3 | such that the type _f (g a)_ can itself be treated
4 | as applicative functor.
5 | -}
6 | package Data.Compose where
7 |
8 | data Compose f g a = Compose { run :: f (g a) }
9 |
10 | compose :: f (g a) -> Compose f g a
11 | compose = Compose
12 |
13 | instance (Functor f, Functor g) => Functor (Compose f g) where
14 | fmap f (Compose fga) = Compose (fmap (fmap f) fga)
15 |
16 | instance (Applicative f, Applicative g) => Applicative (Compose f g) where
17 | pure a = Compose (pure (pure a))
18 | Compose fgf <*> Compose fga = Compose ((<*>) <$> fgf <*> fga)
--------------------------------------------------------------------------------
/tests/comp/Issue284.fr:
--------------------------------------------------------------------------------
1 | --- https://github.com/Frege/frege/issues/284 Issue 284
2 | module tests.comp.Issue284 where
3 |
4 | data Generic' c = Generic' { unGeneric' :: Maybe c }
5 |
6 | access :: Generic' a -> Maybe a
7 | access x = x.unGeneric'
8 |
9 | match :: Generic' a -> Maybe a
10 | match (Generic'{unGeneric'}) = unGeneric'
11 |
12 | match' :: Generic' a -> Maybe a
13 | match' (Generic'{unGeneric'=a}) = a
14 |
15 | update :: b -> Generic' a -> Generic' b
16 | update b x = x.{ unGeneric' = Just b }
17 |
18 | change :: (a -> b) -> Generic' a -> Generic' b
19 | change f x = x.{ unGeneric' <- fmap f }
20 |
21 |
22 | main = println (access (Generic' (Just "O'kay")))
--------------------------------------------------------------------------------
/tests/comp/Issue345.fr:
--------------------------------------------------------------------------------
1 | --- annotated foo = empty generates wrong java code unless same type variables as in original are used
2 | module tests.comp.Issue345 where
3 |
4 | class Leer a where
5 | wüst :: a b
6 |
7 | instance Leer Maybe where
8 | wüst = Nothing
9 |
10 | --- this compiles
11 | leer :: Leer x ⇒ x y
12 | leer = wüst
13 |
14 | --- this didn't (because ListEmpty is special)
15 | empty' :: ListEmpty α ⇒ α y
16 | empty' = empty
17 |
18 |
19 | --- neither this one
20 | epair ∷ (ListEmpty m, ListEmpty n) ⇒ (m Int, n Bool)
21 | epair = (empty, empty)
22 |
23 | kopf ∷ ListView b ⇒ (b a → a, Int)
24 | kopf = (head, 32)
25 |
26 |
27 | main = println (empty :: [String])
--------------------------------------------------------------------------------
/tests/comp/Issue298.fr:
--------------------------------------------------------------------------------
1 | --- see 'https://github.com/Frege/frege/issues/298 Issue 298'
2 | --- Adapt default precedence and associativity to Haskell2010 standard:
3 | --- If no fixity declaration is given for op then it defaults to highest precedence and left associativity.
4 | module tests.comp.Issue298 where
5 |
6 | --- when op is used as operator, it'll bind more tightly than multiplication
7 | op a b = a + b
8 |
9 | example1 = 3 * 4 `op` 5 `op` 6 -- should be 45
10 | example2 = 3 * 4 + 5 + 6 -- should be 23
11 |
12 | (###) = (,)
13 |
14 | also ∷ ((Int,Bool),Char)
15 | also = 1 ### true ### 'c'
16 |
17 | main :: IO Bool
18 | main = pure (example1 == 45 && example2 == 23)
19 |
20 |
--------------------------------------------------------------------------------
/tests/comp/Issue152.fr:
--------------------------------------------------------------------------------
1 | --- Demonstrate working of "MonadFail" issue
2 | module tests.comp.Issue152 where
3 |
4 |
5 | foo xs = [ 2*x | ("this", x) <- xs ]
6 | bar xs = do { ("this", x) <- xs; return (2*x) }
7 |
8 | items = [("this", 21), ("that", 1)]
9 |
10 | main = do
11 | println $ foo items -- [42]
12 | println $ bar items -- used to abort due to pattern match failure
13 | println $ bar (Just ("this", 21)) -- Just 42
14 | println $ (bar (Right ("that", 21)) :: (String | Int)) -- Left "pattern match failure ..."
15 | -- don't disturb interactive regression
16 | -- println "Enter \"quit\" for graceful exit, anything else for abortion."
17 | -- "quit" <- getLine
18 | pure ()
--------------------------------------------------------------------------------
/tests/nocomp/Issue53.fr:
--------------------------------------------------------------------------------
1 | module tests.nocomp.Issue53 where
2 |
3 | {--
4 | See https://github.com/Frege/frege/issues/53
5 |
6 | Type checks without errors, but then in code generation the compiler aborts with:
7 |
8 | > F tests/nocomp/Issues53.fr:14: unknown context: Show <3251 a>
9 |
10 | Correct behaviour would be when the type checker would complain
11 | > E tests/nocomp/Issue53.fr:17: inferred type is more constrained than expected type
12 | > inferred: Show t3252 => [String] -> IO ()
13 | > expected: [String] -> IO ()
14 |
15 | Note that there is the implicit annotation:
16 |
17 | > main :: [String] -> IO ()
18 | -}
19 |
20 | main _ = println []
21 |
--------------------------------------------------------------------------------
/frege/compiler/instances/PositionedSName.fr:
--------------------------------------------------------------------------------
1 | --- 'Positioned' instance for 'SNames'
2 | module frege.compiler.instances.PositionedSName where
3 |
4 | import Compiler.types.SNames
5 | import Compiler.types.Positions
6 |
7 |
8 | instance Positioned SName where
9 | is _ = "simple name"
10 | getpos Simple{id} = Pos id id
11 | getpos With1{ty, id} = Pos it id
12 | where !it = if ty.line < id.line then id else ty
13 | getpos With2{ns, ty, id} = Pos it id
14 | where !it = if ns.line < id.line
15 | then if ty.line < id.line
16 | then id
17 | else ty
18 | else ns
19 | getrange = getpos
20 |
--------------------------------------------------------------------------------
/frege/java/swing/GroupLayout.fr:
--------------------------------------------------------------------------------
1 | {--
2 | Inner classes of javax.swing.GroupLayout
3 | --}
4 | package frege.java.swing.GroupLayout where
5 |
6 | data Alignment = pure native javax.swing.GroupLayout.Alignment where
7 | pure native leading javax.swing.GroupLayout.Alignment.LEADING :: Alignment
8 | pure native trailing javax.swing.GroupLayout.Alignment.TRAILING :: Alignment
9 | pure native center javax.swing.GroupLayout.Alignment.CENTER :: Alignment
10 | pure native baseline javax.swing.GroupLayout.Alignment.BASELINE :: Alignment
11 |
12 |
13 | data ParallelGroup = native javax.swing.GroupLayout.ParallelGroup
14 |
15 |
16 | data Group = native javax.swing.GroupLayout.Group
17 |
--------------------------------------------------------------------------------
/contrib/dgronau/trans/MonadIO.fr:
--------------------------------------------------------------------------------
1 | package frege.control.trans.MonadIO where
2 |
3 | {--
4 | Monads in which 'IO' computations may be embedded.
5 | Any monad built by applying a sequence of monad transformers to the
6 | 'IO' monad will be an instance of this class.
7 |
8 | Instances should satisfy the following laws, which state that 'liftIO'
9 | is a transformer of monads:
10 |
11 | 'liftIO' <~ 'return' = 'return'
12 |
13 | 'liftIO' (m >>= f) = 'liftIO' m >>= ('liftIO' <~ f)
14 |
15 | -}
16 |
17 | class MonadIO Monad m => m where
18 | --- Lift a computation from the 'IO' monad.
19 | liftIO :: IO a -> m a
20 |
21 | instance MonadIO IO where
22 | liftIO io = io
23 | return = ST.return
24 | (>>=) = (ST.>>=)
--------------------------------------------------------------------------------
/tests/comp/Issue284a.fr:
--------------------------------------------------------------------------------
1 | --- https://github.com/Frege/frege/issues/284 Issue 284
2 | ---
3 | --- Tests that imported record can be used even if mangled.
4 | module tests.comp.Issue284a where
5 |
6 | import tests.comp.Issue284 (Generic')
7 |
8 | access :: Generic' a -> Maybe a
9 | access x = x.unGeneric'
10 |
11 | match :: Generic' a -> Maybe a
12 | match (Generic'{unGeneric'}) = unGeneric'
13 |
14 | match' :: Generic' a -> Maybe a
15 | match' (Generic'{unGeneric'=a}) = a
16 |
17 | update :: b -> Generic' a -> Generic' b
18 | update b x = x.{ unGeneric' = Just b }
19 |
20 | change :: (a -> b) -> Generic' a -> Generic' b
21 | change f x = x.{ unGeneric' <- fmap f }
22 |
23 | main = println (access (Generic' (Just "also O'kay")))
--------------------------------------------------------------------------------
/tests/messages/Case1.fr:
--------------------------------------------------------------------------------
1 | --- Code that leads to confusing/wrong error messages
2 | module tests.messages.Case1 where
3 |
4 | {--
5 |
6 | This gives 2 messages on line 20:
7 |
8 | > type error in expression f x type is: a expected: b
9 |
10 | This is correct, but could be more explicit by pointing out that
11 | - @f x :: a@ because @f :: b->a@ and @x :: b@
12 | - @f x :: b@ because @f :: b->a@ and @f (f b) :: a@
13 |
14 | > type `b` is not as polymorphic as suggested in the annotation where just `a` is announced.
15 |
16 | This is confusing and also wrong.
17 |
18 | Resolution: This message should be suppressed if there is already a type error.
19 | -}
20 | twice ∷ (a→b) → a → b
21 | twice f x = f (f x :: String)
--------------------------------------------------------------------------------
/examples/TailCalls.fr:
--------------------------------------------------------------------------------
1 | {--
2 |
3 | Demonstration of dealing with tail calls in Frege
4 |
5 | -}
6 | module examples.TailCalls
7 | inline(odd)
8 | where
9 |
10 | -- hide the standard functions even and odd which work with bitmasks
11 | import frege.Prelude hiding(even, odd)
12 |
13 | --- Check evenness by downcounting
14 | --- To be sure, we would normally do this by checking the rightmost bit in O(1)
15 | --- This code is solely for demonstration purposes
16 | even :: Int -> Bool
17 | even 0 = true
18 | even 1 = false
19 | even n = odd (pred n)
20 |
21 | odd :: Int -> Bool
22 | odd n = even (pred n)
23 |
24 | -- odd n = not (even (n-1))
25 |
26 | main [arg] = println . even . atoi $ arg
27 | main _ = println (even 123456789)
28 |
--------------------------------------------------------------------------------
/tests/comp/Issue234.fr:
--------------------------------------------------------------------------------
1 | {--
2 | Test code for for 'https://github.com/Frege/frege/issues/234 Issue 234'
3 |
4 | This code used to complain about ambiguous overloads:
5 |
6 | > overloaded new is ambiguous at type String→U
7 | > It could mean one of
8 | > U.newα :: String → U
9 | > U.newβ :: String → Throwable → U
10 | > A.new :: String → U
11 | -}
12 |
13 | module tests.comp.Issue234 where
14 |
15 | data U = pure native frege.runtime.Undefined where
16 | pure native new :: String -> U | String -> Throwable -> U
17 |
18 | data A = pure native java.lang.IllegalArgumentException where
19 | pure native new :: String -> U
20 |
21 | x = U.new "foo" :: U
22 |
23 | main = println "Ok, since compiled."
24 |
--------------------------------------------------------------------------------
/tests/comp/Issue355.fr:
--------------------------------------------------------------------------------
1 | --- 'https://github.com/Frege/frege/issues/355 Issue #355'
2 | --- Type checking aborts with "bad types in unification" with @(extends Object)@ construct
3 | module tests.comp.Issue355 where
4 |
5 | native forN java.lang.Class.forName :: String -> IO (Class (≤Object)) throws ClassNotFoundException
6 |
7 |
8 | -- frege> forN "java.lang.Object"
9 | -- IO (Class (≤Object))
10 |
11 | idc :: Class (≤Object) -> IO (Class Object)
12 | idc x = pure x
13 |
14 | idx x = pure x
15 |
16 | value1 :: IO (Class Object)
17 | value1 = (forN "java.lang.Object") >>= idx
18 |
19 | value2 = forN "java.lang.Object" >>= idc
20 |
21 | main :: IO Bool
22 | main = do
23 | value1 >>= println . _.getName
24 | value2 >>= println . _.getName
25 | pure true
--------------------------------------------------------------------------------
/frege/data/wrapper/Dual.fr:
--------------------------------------------------------------------------------
1 | --- Provides a wrapper for a 'Monoid' that works in reverse
2 | module Data.wrapper.Dual where
3 |
4 | import Data.Monoid
5 |
6 | --- Provides a 'Monoid' where 'mappend' appears flipped.
7 | newtype Dual a = Dual { unwrap :: a } --- wrap a value to give a 'Dual'
8 | derive Show (Dual a)
9 | derive Eq (Dual a)
10 | derive Ord (Dual a)
11 |
12 | --- get the value wrapped by 'Dual' (Haskell compatibility)
13 | getDual = Dual.unwrap
14 |
15 | instance Semigroup a => Semigroup (Dual a) where
16 | --- > Dual "foo" <> Dual "bar" == Dual "barfoo"
17 | Dual x `mappend` Dual y = Dual (mappend y x)
18 |
19 | instance Monoid a => Monoid (Dual a) where
20 | --- @Dual e@ where @e@ is the identity of the wrapped value.
21 | mempty = Dual mempty
22 |
23 |
--------------------------------------------------------------------------------
/frege/compiler/types/JNames.fr:
--------------------------------------------------------------------------------
1 | --- Model of Java names.
2 | module frege.compiler.types.JNames where
3 |
4 | --- A Java name
5 | --- The 'JName.qual' part may have "." in it, or may be empty for unqualified names.
6 | --- The 'JName.base' part will be a simple 'String' for the last component.
7 | data JName = !JName {qual :: String, base :: String}
8 |
9 | instance Show JName where
10 | show (JName "" x) = x
11 | show (JName p x) = p ++ "." ++ x
12 |
13 | instance Eq JName where
14 | ja == jb = show ja == show jb
15 | hashCode ja = hashCode ja.show
16 |
17 |
18 |
19 |
20 | {--
21 | Given a 'JName' and a member name, returns the 'JName' of the member.
22 | -}
23 | memberOf (JName "" b) c = JName b c
24 | memberOf (JName a b) c = JName (a++"."++b) c
25 |
26 |
27 |
--------------------------------------------------------------------------------
/tests/qc/PierresPrime.fr:
--------------------------------------------------------------------------------
1 | --- Issue #218
2 | module tests.qc.PierresPrime where
3 |
4 | import Test.QuickCheck
5 |
6 | prime' = f firstPrime
7 | where
8 | f n x = if (n < x)
9 | then if (mod x n == 0)
10 | then false
11 | else f (succ n) x
12 | else true
13 | firstPrime = 2
14 |
15 | prime :: (Enum a, Integral a) => a -> Bool
16 | prime = f firstPrime
17 | where
18 | f n x = if (n < x)
19 | then if (mod x n == 0)
20 | then false
21 | else f (succ n) x
22 | else true
23 | firstPrime = 2
24 |
25 | pierres_property = once (not (prime' 9) && not (prime 9))
26 |
27 | main :: IO ()
28 | main = do
29 | println $ prime' 9
30 | println $ prime 9
--------------------------------------------------------------------------------
/tests/comp/TDNR.fr:
--------------------------------------------------------------------------------
1 | --- interplay of type directed name resolution and overload resolution
2 | --- cover cases where TDNR on @x.m@ is only possible after overload resolution
3 | module tests.comp.TDNR where
4 | import Java.Net(URI, URL)
5 |
6 |
7 | x = _.startsWith "/" $ _.getPath $ File.new "/tmp"
8 |
9 |
10 | y = _.toURL $ _.toURI $ File.new "/tmp"
11 | -- _.toURL <$> (File.new "/tmp" >>= readonly _.toURI) -- before changing File to pure
12 | -- (File.new "/tmp" >>= readonly _.toURI >>= pure . _.toURL) -- did typecheck before 3.25.49
13 | -- clearly showing left-right bias
14 |
15 | main :: IO Bool
16 | main = do
17 | println x
18 | println . either Throwable.show _.toString $ y
19 | pure true
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | text=auto
3 |
4 | *.jar binary
5 | *.png binary
6 | *.jpg binary
7 | *.jpeg binary
8 | *.ico binary
9 | *.class binary
10 |
11 | *.pl text
12 | *.fr text
13 | *.java text
14 | *.y text
15 | Makefile text
16 | *.mk text
17 |
18 | # Custom for Visual Studio
19 | *.cs diff=csharp
20 | *.sln merge=union
21 | *.csproj merge=union
22 | *.vbproj merge=union
23 | *.fsproj merge=union
24 | *.dbproj merge=union
25 |
26 | # Standard to msysgit
27 | *.doc diff=astextplain
28 | *.DOC diff=astextplain
29 | *.docx diff=astextplain
30 | *.DOCX diff=astextplain
31 | *.dot diff=astextplain
32 | *.DOT diff=astextplain
33 | *.pdf diff=astextplain
34 | *.PDF diff=astextplain
35 | *.rtf diff=astextplain
36 | *.RTF diff=astextplain
37 |
--------------------------------------------------------------------------------
/examples/GoldenRatio.fr:
--------------------------------------------------------------------------------
1 | --- Compute and print the golden ratio
2 | module examples.GoldenRatio where
3 |
4 | import Data.List (dropUntil)
5 |
6 | fibs = 1:1:zipWith (+) fibs (tail fibs) :: [Long]
7 |
8 | infix 6 ***
9 |
10 | (***) n = packed . replicate n
11 |
12 | main _ = do
13 | println ("The golden ratio is " ++ show golden
14 | ++ " = (" ++ show nom ++ "/" ++ show denom ++ ")")
15 | -- print a 48x30 box of stars
16 | replicateM_ 30 (println ((30*golden).long.int *** '*'))
17 | where
18 | golden = nom.double / denom.double
19 | (denom, nom) = head . dropUntil closeEnough . zip fibs $ (tail fibs)
20 | closeEnough (d,n) = abs (a-b) < 1.0e-9
21 | where
22 | b = Long.double n / Long.double d
23 | a = (1+b)/b
24 |
25 |
--------------------------------------------------------------------------------
/frege/compiler/enums/Visibility.fr:
--------------------------------------------------------------------------------
1 | --- cross module visibility of items
2 | module frege.compiler.enums.Visibility where
3 |
4 | --- cross module visibility of items
5 | data Visibility =
6 | Private --- item is not available in other packages, except constructors for inlined code
7 | | Protected --- item is available but will be imported only on demand
8 | | Public --- item is available and will be imported by default
9 | | Abstract --- makes type public but all constructors private
10 |
11 | instance Show Visibility where
12 | show Private = "private"
13 | show Public = "public"
14 | show Protected = "protected"
15 | show Abstract = "abstract"
16 |
17 |
18 | derive Eq Visibility
19 |
20 |
21 | derive Ord Visibility
22 |
23 |
24 |
--------------------------------------------------------------------------------
/tests/comp/Issue126.fr:
--------------------------------------------------------------------------------
1 | --- Example code for Issue 126
2 | module tests.comp.Issue126 where
3 |
4 | import frege.Prelude hiding(Byte)
5 | -- import Data.List
6 |
7 | data Byte = pure native "byte" where
8 | pure native byte "(byte)" :: Int -> Byte
9 | --- this gives the 'Int' corresponding to the *signed* interpretation of the 'Byte'
10 | pure native signed "(int)" :: Byte -> Int
11 | --- this gives the 'Int' corresponding to the *unsigned* interpretation of the 'Byte'
12 | unsigned b = signed b Int..&. 0xFF
13 | hashCode = Byte.unsigned
14 |
15 | instance Eq Byte where
16 | -- hashCode = Byte.unsigned
17 | pure native == :: Byte -> Byte -> Bool
18 | pure native != :: Byte -> Byte -> Bool
19 |
20 | main = print (hashCode (Byte.byte 142)) >> println " (should be 142)"
--------------------------------------------------------------------------------
/tests/comp/Issue21.fr:
--------------------------------------------------------------------------------
1 | {--
2 | Should compile if type aliases work more like macros like in
3 | http://www.haskell.org/ghc/docs/latest/html/users_guide/data-type-extensions.html#type-synonyms
4 | -}
5 | module tests.comp.Issue21 where
6 |
7 | --- Lens type
8 | type Lens' s a = forall f. Functor f => (a -> f a) -> s -> f s
9 |
10 | --- You can write a forall (including overloading) in a type synonym, thus:
11 | type Discard a = forall b. Show b => a -> b -> (a, String)
12 |
13 |
14 |
15 | f :: Discard c
16 | -- f :: forall b c. Show b => c -> b -> (c, String)
17 | f x y = (x, show y)
18 |
19 | g :: Discard Int -> (Int,String) -- A rank-2 type
20 | -- g :: (forall b . Show b => Int -> b -> (Int, String)) -> (Int, String)
21 | g f = f 3 true
22 |
23 | h = g f
24 |
25 |
26 | main _ = println h
--------------------------------------------------------------------------------
/frege/control/monad/trans/MonadIO.fr:
--------------------------------------------------------------------------------
1 | --- Monads in which 'IO' computations may be embedded.
2 | package frege.control.monad.trans.MonadIO
3 | inline (IO.liftIO)
4 | where
5 |
6 | {--
7 | Monads in which 'IO' computations may be embedded.
8 |
9 | Any monad built by applying a sequence of monad transformers to the
10 | 'IO' monad will be an instance of this class.
11 |
12 | Instances should satisfy the following laws, which state that 'liftIO'
13 | is a transformer of monads:
14 |
15 | > liftIO . return = return
16 |
17 | > liftIO (m >>= f) = liftIO m >>= (liftIO . f)
18 |
19 | -}
20 |
21 | class Monad m => MonadIO m where
22 | --- Lift a computation from the 'IO' monad.
23 | liftIO :: IO a -> m a
24 |
25 | instance MonadIO IO where
26 | liftIO = id
27 |
--------------------------------------------------------------------------------
/tests/comp/Issue103.fr:
--------------------------------------------------------------------------------
1 | --- Code for 'https://github.com/Frege/frege/issues/103 Issue 103'
2 | module tests.comp.Issue103 where
3 |
4 | --- Tail recursion must pass an updated context in each turn.
5 | --- Note that the value that is finally shown is of type
6 | --- > [[[ ... 𝖆 ... ]]]
7 | --- where the 'Int' argument determines the number of @[]@ pairs.
8 | --- In the 3.22 release, this works only when there is no tail recursion.
9 | nested ∷ Show 𝖆 ⇒ Int → 𝖆 → String
10 | nested 0 x = show x
11 | nested n x = nested (n-1) (x,x)
12 | -- when polymorphic tail recursion works,
13 | -- the following line can be commented
14 | -- ++ ""
15 |
16 | main [arg] = do
17 | println "module Stress where"
18 | print "val = "
19 | println (nested (atoi arg) true)
20 | main _ = main ["3"]
21 |
--------------------------------------------------------------------------------
/frege/data/wrapper/Ord.fr:
--------------------------------------------------------------------------------
1 | --- 'Monoid' instances for bounded and ordered values, using 'min' and 'max'
2 | module frege.data.wrapper.Ord where
3 |
4 | import Data.Monoid
5 |
6 |
7 | newtype Min a = Min { unwrap :: a }
8 | derive Show (Min a)
9 | derive Eq (Min a)
10 | derive Ord (Min a)
11 |
12 | getMin = Min.unwrap
13 |
14 | instance (Ord a, Bounded a) => Monoid (Min a) where
15 | mempty = Min maxBound
16 | instance Ord a => Semigroup (Min a) where
17 | Min a `mappend` Min b = Min (a `min` b)
18 |
19 |
20 | newtype Max a = Max { unwrap :: a }
21 | derive Show (Max a)
22 | derive Eq (Max a)
23 | derive Ord (Max a)
24 |
25 | getMax = Max.unwrap
26 |
27 | instance (Ord a, Bounded a) => Monoid (Max a) where
28 | mempty = Max minBound
29 | instance Ord a => Semigroup (Max a) where
30 | Max a `mappend` Max b = Max (a `max` b)
31 |
--------------------------------------------------------------------------------
/tests/comp/Issue80.fr:
--------------------------------------------------------------------------------
1 | --- See 'https://github.com/Frege/frege/issues/80 the corresponding issue'
2 | module tests.comp.Issue80 where
3 |
4 | g :: ((forall b. [b] → [b]) → Int) → Int
5 | g f = undefined
6 |
7 |
8 | k1 :: (forall a. a -> a) -> Int
9 | k1 f = undefined
10 |
11 | k2 :: ([Long] -> [Long]) -> Int
12 | k2 = undefined
13 |
14 |
15 | -- dosNotWork = g k1
16 |
17 | shouldBeInt = g k2
18 |
19 | type I c = forall e. c e → c e
20 |
21 | data T (b ∷ * → *) =
22 | TA (forall 𝖆.b 𝖆 -> b 𝖆)
23 | | TB (I b)
24 | | TC { func :: forall 𝖉.Num 𝖉 => b 𝖉 -> b 𝖉 }
25 | | TD { fund :: I Maybe } where
26 | a ←→ b = a b
27 |
28 | infix 5 T.←→
29 |
30 |
31 | y = TB reverse
32 | z = TC (fmap (1+))
33 |
34 | -- x :: T (𝖟 :: * → *)
35 | x = TD (fmap id)
36 |
37 | main = println (z.func (Just 42))
38 | -- z = TC Int.abs
39 |
--------------------------------------------------------------------------------
/frege/compiler/classes/QNameMatcher.fr:
--------------------------------------------------------------------------------
1 | --- Blur the difference between 'QName' and 'Sname' as far as display of items is concerned.
2 | module frege.compiler.classes.QNameMatcher where
3 |
4 | import Compiler.types.Tokens
5 | import Compiler.types.SNames
6 | import Compiler.types.Packs
7 | import Compiler.types.QNames
8 | import Compiler.types.Global as G
9 |
10 |
11 | --- helper type class to make 'unAlias' type-wise work on all 'TauT'
12 | protected class QNameMatcher n where
13 | private match :: Global -> n -> QName -> Bool
14 | private fakeQName :: n -> QName
15 |
16 |
17 | instance QNameMatcher SName where
18 | match _ _ _ = false
19 | fakeQName s = TName (Pack.new "fake.Pack") s.id.value
20 |
21 |
22 | instance QNameMatcher QName where
23 | match g q1 q2 = g.findit q1 == g.findit q2
24 | fakeQName q = q
25 |
26 |
--------------------------------------------------------------------------------
/tests/comp/Issue297.fr:
--------------------------------------------------------------------------------
1 | {--
2 | when compiling with -O
3 |
4 | > E tests/comp/Issue297.fr:18: Cannot make lambda that has no function type
5 | > λv2338 -> mkT id' (mkT id' v2338) :: a → a @@ Lazy