Re: [Haskell-cafe] Re: Haskell is a scripting language inspired by Python.
Hello, reading this thread a question came to me: Is there a way of automatically deriving programming languages ascendancy? Like biologist can determine the distance between two genotypes, and determine a hierarchy between species from that. Are you aware of researchs made in the field? On the net I found interesting graphs but no comments on the methodology. http://www.levenez.com/lang/ http://rigaux.org/language-study/diagram.html Cheers, Corentin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] How can I use MACID in my existing application?
Hello, I'm wondering how can I use Happstack's MACID in my application without breaking everything. I have a monad like that: type Comm = StateT Communication IO type GameState a = StateT Game Comm a and many functions like: foo :: GameState () foo = do lift $ putComm some message to player's channel modify someAction The state of the game is stored in Game. Comm is used as an abstraction to communicate over several channels with players. Whereas MACID asks to use: type *Update* state = Evhttp://happstack.com/docs/0.5.0/happstack-state/Happstack-State.html#t%3AEv( StateThttp://happstack.com/docs/0.5.0/mtl/Control-Monad-State-Lazy.html#t%3AStateTstate STM http://happstack.com/docs/0.5.0/base/GHC-Conc.html#t%3ASTM) How can I use this without modifying everything?? I understand that MACID must record the someAction from above but the message should not. Thanks for help! Corentin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Fwd: [Haskell-cafe] DSL libraries
Nobody had the compilation messages I had? -- Forwarded message -- From: Dupont Corentin corentin.dup...@gmail.com Date: Tue, Nov 2, 2010 at 2:30 PM Subject: [Haskell-cafe] DSL libraries (Was: Map constructor in a DSL) To: steffen steffen.sier...@googlemail.com, haskell-cafe@haskell.org Hello Steffen, can you compile AwesomePrelude? I've got error messages (see below). By the way, I've looked at some DSLs made in Haskell, if I don't mistake there are lots of similarities between them. There similarities could be put in a library to help the implementors of a DSL, more or less like AwesomePrelude. Is there already packages on Hackage dealing with that? Cheers, Corentin AwesomePrelude compilation error: I'm using GHC 6.12.1. cd tomlokhorst-AwesomePrelude-9819315 cabal install (...) Warning: Lang.Haskell: Instances of type and data families are not yet supported. Instances of the following families will be filtered out: H Then, when trying with a very simple GATD in GHCI, I've got: interactive: HSAwesomePrelude-0.1.0.o: unknown symbol `AwesomePreludezm0zi1zi0_ CompilerziLiftDefinitions_inline_closure' ghc: unable to load package `AwesomePrelude-0.1.0' On Thu, Oct 28, 2010 at 2:02 PM, steffen steffen.sier...@googlemail.comwrote: I think you would love to have a look at AwesomePrelude[1] or a fork of AwesomePrelude using associated types[2] Some more background information by Tom Lokhorst [3][4]. [1] http://github.com/tomlokhorst/AwesomePrelude [2] http://github.com/urso/AwesomePrelude [3] http://tom.lokhorst.eu/2009/09/deeply-embedded-dsls [4] http://tom.lokhorst.eu/2010/02/awesomeprelude-presentation-video On 28 Okt., 12:09, Dupont Corentin corentin.dup...@gmail.com wrote: Thank you for your rich responses. Indeed I think I miss some thinks in my DSL, that would make things easier to deal with lists and first class functions. I don't really know what for now. Perhaps a List Constructor? Or a constructor on functions like yours Ryan? EAp :: Exp ref (a - b) - Exp ref a - Exp ref b It's from which DSL? It is accessible on the net? Chris suggested me that I can only define the Foldr constructor and deduce Map from it. But maybe I have to add a List constructor for that. But in the suggestions from Ryan and Brandon I don't understand why I should add an extra type parameter and what it is! Steffen: Wow nice. I'll integrate that ;) I'm also looking at the Atom's DSL to get inspiration. Something I don't understand in it is that it has two languages, on typed: data E a where VRef:: V a - E a Const :: a - E a Cast:: (NumE a, NumE b) = E a - E b Add :: NumE a = E a - E a - E a etc. And, along with it, an untyped counterpart: -- | An untyped term. data UE = UVRef UV | UConst Const | UCast Type UE | UAdd UE UE etc. What that for? What's the use of having beautiful GADT if you have to maintain an untyped ADT aside?? Corentin ___ Haskell-Cafe mailing list haskell-c...@haskell.orghttp:// www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] DSL libraries
Hello, With your version it compiles. Thanks. Corentin On Thu, Nov 4, 2010 at 7:03 PM, Sebastiaan Visser s...@fvisser.nl wrote: Dupont, The `AwesomePrelude' (we apologize for this name) is a very experimental project that is not a workable library or executable at all. You can better consider it to be a `bunch of code' with some interesting ideas and some interesting potential. At least my branch[1] runs on my machine and I'm still able to produce javascript code. But don't expect it to solve any of your problems. ;-) We (at least I) still have some ideas for this project and hope we can someday revive it. Cheers, Sebastiaan [1] https://github.com/sebastiaanvisser/AwesomePrelude On Nov 4, 2010, at 6:51 PM, Dupont Corentin wrote: Nobody had the compilation messages I had? -- Forwarded message -- From: Dupont Corentin corentin.dup...@gmail.com Date: Tue, Nov 2, 2010 at 2:30 PM Subject: [Haskell-cafe] DSL libraries (Was: Map constructor in a DSL) To: steffen steffen.sier...@googlemail.com, haskell-cafe@haskell.org Hello Steffen, can you compile AwesomePrelude? I've got error messages (see below). By the way, I've looked at some DSLs made in Haskell, if I don't mistake there are lots of similarities between them. There similarities could be put in a library to help the implementors of a DSL, more or less like AwesomePrelude. Is there already packages on Hackage dealing with that? Cheers, Corentin AwesomePrelude compilation error: I'm using GHC 6.12.1. cd tomlokhorst-AwesomePrelude-9819315 cabal install (...) Warning: Lang.Haskell: Instances of type and data families are not yet supported. Instances of the following families will be filtered out: H Then, when trying with a very simple GATD in GHCI, I've got: interactive: HSAwesomePrelude-0.1.0.o: unknown symbol `AwesomePreludezm0zi1zi0_ CompilerziLiftDefinitions_inline_closure' ghc: unable to load package `AwesomePrelude-0.1.0' On Thu, Oct 28, 2010 at 2:02 PM, steffen steffen.sier...@googlemail.com wrote: I think you would love to have a look at AwesomePrelude[1] or a fork of AwesomePrelude using associated types[2] Some more background information by Tom Lokhorst [3][4]. [1] http://github.com/tomlokhorst/AwesomePrelude [2] http://github.com/urso/AwesomePrelude [3] http://tom.lokhorst.eu/2009/09/deeply-embedded-dsls [4] http://tom.lokhorst.eu/2010/02/awesomeprelude-presentation-video On 28 Okt., 12:09, Dupont Corentin corentin.dup...@gmail.com wrote: Thank you for your rich responses. Indeed I think I miss some thinks in my DSL, that would make things easier to deal with lists and first class functions. I don't really know what for now. Perhaps a List Constructor? Or a constructor on functions like yours Ryan? EAp :: Exp ref (a - b) - Exp ref a - Exp ref b It's from which DSL? It is accessible on the net? Chris suggested me that I can only define the Foldr constructor and deduce Map from it. But maybe I have to add a List constructor for that. But in the suggestions from Ryan and Brandon I don't understand why I should add an extra type parameter and what it is! Steffen: Wow nice. I'll integrate that ;) I'm also looking at the Atom's DSL to get inspiration. Something I don't understand in it is that it has two languages, on typed: data E a where VRef:: V a - E a Const :: a - E a Cast:: (NumE a, NumE b) = E a - E b Add :: NumE a = E a - E a - E a etc. And, along with it, an untyped counterpart: -- | An untyped term. data UE = UVRef UV | UConst Const | UCast Type UE | UAdd UE UE etc. What that for? What's the use of having beautiful GADT if you have to maintain an untyped ADT aside?? Corentin ___ Haskell-Cafe mailing list haskell-c...@haskell.orghttp:// www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] DSL libraries (Was: Map constructor in a DSL)
Hello Steffen, can you compile AwesomePrelude? I've got error messages (see below). By the way, I've looked at some DSLs made in Haskell, if I don't mistake there are lots of similarities between them. There similarities could be put in a library to help the implementors of a DSL, more or less like AwesomePrelude. Is there already packages on Hackage dealing with that? Cheers, Corentin AwesomePrelude compilation error: I'm using GHC 6.12.1. cd tomlokhorst-AwesomePrelude-9819315 cabal install (...) Warning: Lang.Haskell: Instances of type and data families are not yet supported. Instances of the following families will be filtered out: H Then, when trying with a very simple GATD in GHCI, I've got: interactive: HSAwesomePrelude-0.1.0.o: unknown symbol `AwesomePreludezm0zi1zi0_ CompilerziLiftDefinitions_inline_closure' ghc: unable to load package `AwesomePrelude-0.1.0' On Thu, Oct 28, 2010 at 2:02 PM, steffen steffen.sier...@googlemail.comwrote: I think you would love to have a look at AwesomePrelude[1] or a fork of AwesomePrelude using associated types[2] Some more background information by Tom Lokhorst [3][4]. [1] http://github.com/tomlokhorst/AwesomePrelude [2] http://github.com/urso/AwesomePrelude [3] http://tom.lokhorst.eu/2009/09/deeply-embedded-dsls [4] http://tom.lokhorst.eu/2010/02/awesomeprelude-presentation-video On 28 Okt., 12:09, Dupont Corentin corentin.dup...@gmail.com wrote: Thank you for your rich responses. Indeed I think I miss some thinks in my DSL, that would make things easier to deal with lists and first class functions. I don't really know what for now. Perhaps a List Constructor? Or a constructor on functions like yours Ryan? EAp :: Exp ref (a - b) - Exp ref a - Exp ref b It's from which DSL? It is accessible on the net? Chris suggested me that I can only define the Foldr constructor and deduce Map from it. But maybe I have to add a List constructor for that. But in the suggestions from Ryan and Brandon I don't understand why I should add an extra type parameter and what it is! Steffen: Wow nice. I'll integrate that ;) I'm also looking at the Atom's DSL to get inspiration. Something I don't understand in it is that it has two languages, on typed: data E a where VRef:: V a - E a Const :: a - E a Cast:: (NumE a, NumE b) = E a - E b Add :: NumE a = E a - E a - E a etc. And, along with it, an untyped counterpart: -- | An untyped term. data UE = UVRef UV | UConst Const | UCast Type UE | UAdd UE UE etc. What that for? What's the use of having beautiful GADT if you have to maintain an untyped ADT aside?? Corentin ___ Haskell-Cafe mailing list haskell-c...@haskell.orghttp:// www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] State nested structures
Hello the list, I have another silly question. In my software I have a very common pattern: --in file A.hs module A where data A = A {b :: B, i :: Int} type SA x = State A x -- many functions with SA x --in file B.hs data B = B {r :: Int} type SB x = State B x -- many functions with SB x Of course in module A I'm calling some functions of module B. I'd like to know if it's possible, in a function of type SA, to call a function of type SB, without actually executing the State SB. I just wanna tell him Hey look, you can construct a SA from a SB like this! For now I have this: bToA:: (B - B) - A - A bToA bb = (λa - a{b = bb (b a)}) useB :: SB () - SA () useB = modify . bToA . execState Can I get rid of the execState? Also, I can't manage to write the more generic function SB x - SA x. Cheers, Corentin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: State nested structures
Thank you for your responses. I will look at monad transformers. I already use them I think because actually I use something like StateT Game IO a. You mean I have to implement my own instance? Oh, can you call me Corentin? This is my name ;) Cheers, Corentin On Fri, Oct 29, 2010 at 6:19 PM, steffen steffen.sier...@googlemail.comwrote: Horribly enough this one seems to work... mapOnBofA :: SB a - SA a mapOnBofA mf = get = \st@(A {b=temp}) - let (ans,temp2) = runState mf temp in put (st { b=temp2}) return ans There is nothing horrible about that. You just run a new isolated computation in the State Monad for B and use its results. More or less see same solution as Dupont's. @Dupont: telling from your possible use case and your last post with your MAP- Problem, these two are very similar. You have a monad and inside your monad you temporarily want to run some computation in another Monad. I think Monad-Transformers are maybe the better option for you (especially your interpreter-Problem was a good use case for StateT/ ErrorT instead of State and some Either inside it...). On 29 Okt., 17:35, Stephen Tetley stephen.tet...@gmail.com wrote: 2010/10/29 Dupont Corentin corentin.dup...@gmail.com: Also, I can't manage to write the more generic function SB x - SA x. However, I'd have to question why you want both SA and SB as state functional types. Having inner runState's is sometimes good practice (its an instance of the Local Effect pattern identified by Ralf Laemmel and Joost Visser), but if you have it commonly I'd suspect you design is somehow contrived and could be simplified. ___ Haskell-Cafe mailing list haskell-c...@haskell.orghttp:// www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Map constructor in a DSL
Thank you for your rich responses. Indeed I think I miss some thinks in my DSL, that would make things easier to deal with lists and first class functions. I don't really know what for now. Perhaps a List Constructor? Or a constructor on functions like yours Ryan? EAp :: Exp ref (a - b) - Exp ref a - Exp ref b It's from which DSL? It is accessible on the net? Chris suggested me that I can only define the Foldr constructor and deduce Map from it. But maybe I have to add a List constructor for that. But in the suggestions from Ryan and Brandon I don't understand why I should add an extra type parameter and what it is! Steffen: Wow nice. I'll integrate that ;) I'm also looking at the Atom's DSL to get inspiration. Something I don't understand in it is that it has two languages, on typed: data E a where VRef:: V a - E a Const :: a - E a Cast:: (NumE a, NumE b) = E a - E b Add :: NumE a = E a - E a - E a etc. And, along with it, an untyped counterpart: -- | An untyped term. data UE = UVRef UV | UConst Const | UCast Type UE | UAdd UE UE etc. What that for? What's the use of having beautiful GADT if you have to maintain an untyped ADT aside?? Corentin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Map constructor in a DSL
This is really cool. The blog post [3] finally explained to me why I had so much difficulties implementing the Equal constructor ;) I shared this in a previous thread: http://osdir.com/ml/haskell-cafe@haskell.org/2010-06/msg00369.html Maybe latter I'll shift to a class type based DSL. They seem more generic than data type based. Corentin On Thu, Oct 28, 2010 at 2:02 PM, steffen steffen.sier...@googlemail.comwrote: I think you would love to have a look at AwesomePrelude[1] or a fork of AwesomePrelude using associated types[2] Some more background information by Tom Lokhorst [3][4]. [1] http://github.com/tomlokhorst/AwesomePrelude [2] http://github.com/urso/AwesomePrelude [3] http://tom.lokhorst.eu/2009/09/deeply-embedded-dsls [4] http://tom.lokhorst.eu/2010/02/awesomeprelude-presentation-video On 28 Okt., 12:09, Dupont Corentin corentin.dup...@gmail.com wrote: Thank you for your rich responses. Indeed I think I miss some thinks in my DSL, that would make things easier to deal with lists and first class functions. I don't really know what for now. Perhaps a List Constructor? Or a constructor on functions like yours Ryan? EAp :: Exp ref (a - b) - Exp ref a - Exp ref b It's from which DSL? It is accessible on the net? Chris suggested me that I can only define the Foldr constructor and deduce Map from it. But maybe I have to add a List constructor for that. But in the suggestions from Ryan and Brandon I don't understand why I should add an extra type parameter and what it is! Steffen: Wow nice. I'll integrate that ;) I'm also looking at the Atom's DSL to get inspiration. Something I don't understand in it is that it has two languages, on typed: data E a where VRef:: V a - E a Const :: a - E a Cast:: (NumE a, NumE b) = E a - E b Add :: NumE a = E a - E a - E a etc. And, along with it, an untyped counterpart: -- | An untyped term. data UE = UVRef UV | UConst Const | UCast Type UE | UAdd UE UE etc. What that for? What's the use of having beautiful GADT if you have to maintain an untyped ADT aside?? Corentin ___ Haskell-Cafe mailing list haskell-c...@haskell.orghttp:// www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Test command line programs
Thanks for your responses. Of course I already test every pure parts of my program easily. For now, user input is treated in 2 different ways: - direct IO with hgetLine and like functions (blocking) - the same but I directly push the strings on a TChan for another thread to treat them (not blocking). The second is easy to test, since all I have to do is to insert test strings on the TChan to simulate user's input. Maybe I can do everything this way. But for example I had a bug of two threads inter-blocked on the handle. These tests were not able to show it, since the test takes place not on the handle itself but a little after. Maybe mock handle can help. Corentin On Tue, Oct 26, 2010 at 11:32 PM, Antoine Latter aslat...@gmail.com wrote: On Tue, Oct 26, 2010 at 11:11 AM, Dupont Corentin corentin.dup...@gmail.com wrote: Hello again café, I have a command line program that takes input from various handles (actually network sockets) like this: s - hGetLine h etc. I'd like to unit test this. How can I do? I'd like to inject data on the handle so that all the input chain is tested. I haven't tested it yet, but this mock handle will eventually work in GHC 7: http://hackage.haskell.org/trac/ghc/attachment/ticket/4144/ByteStringHandle.hs At least, the bug report about how it didn't work has now been closed :-) I don't remember which operations worked and which didn't - getChar would work, but getContents would fail. The others have great advice, that you should try to isolate the logic of your code from IO for precisely this reason - so it is easily testable. Antoine ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Map constructor in a DSL
Hello café, I have a little DSL in my program as follow. Now I'd like to add a Map constructor in it. Thats where I would need help! data Obs a where AllPlayers :: Obs [Int] Plus :: (Num a) = Obs a - Obs a - Obs a And:: Obs Bool - Obs Bool - Obs Bool Vote :: Obs String - Obs Int - Obs Bool *Map:: (Obs a - Obs b) - Obs [a] - Obs [b]* -- and others Here is the evaluator for Obs: evalObs :: Obs a - Evaluator a evalObs (Konst a) = return $ pure a evalObs (Not a) = liftE not (evalObs a) evalObs (Plus a b) = liftE2 (+) (evalObs a) (evalObs b) evalObs (Minus a b) = liftE2 (-) (evalObs a) (evalObs b) evalObs (Time a b) = liftE2 (*) (evalObs a) (evalObs b) evalObs (And a b) = liftE2 () (evalObs a) (evalObs b) evalObs (Or a b)= liftE2 (||) (evalObs a) (evalObs b) evalObs (Equ a b) = liftE2 (==) (evalObs a) (evalObs b) evalObs (If a b c) = liftE3 (if3) (evalObs a) (evalObs b) (evalObs c) How you can see it is quite neat... But how can I write the evaluator for Map? Actually I have some half baked solution, 15 lines long that I don't dare to show ;) Actually compiling code excerpt is here: http://hpaste.org/40897/map_contstructor_in_a_dsl Thanks for your help. Corentin Below is some helper code: type Evaluator a = StateT Game Comm a (Either Actions a) -- | Combined lifters for Evaluator liftE = liftM . liftA liftE2 = liftM2 . liftA2 liftE3 = liftM3 . liftA3 instance Applicative (Either Actions) where pure x = Right x (Right f) * (Right x) = Right $ f x (Right _) * (Left u) = Left u (Left u) * (Right _) = Left u (Left u) * (Left v) = Left $ u ++ v ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Test command line programs
Hello again café, I have a command line program that takes input from various handles (actually network sockets) like this: s - hGetLine h etc. I'd like to unit test this. How can I do? I'd like to inject data on the handle so that all the input chain is tested. How are command line programs' IO automatically tested usually? Another little question: How can I access the name of a function inside a function (for Trace purpose)? I have to use the CPP preprocessor? Thanks for hints, Corentin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Map constructor in a DSL
Hey Chris! Values for PlayerNumber are acquired at evaluation time, from the state of the system. I have not included the evaluation of AllPlayers. Here how it looks: evalObs AllPlayers = return . pure = gets players But when you build your Obs, you have yet no idea how much players it will be. This is just symbolic at this stage. To give you a better insight, here is want I want to do with Map: everybodyVote :: Obs [Bool] everybodyVote = Map (Vote (Konst Please vote)) AllPlayers In memory, everybodyVote is just a tree. This rule can be executed latter whenever I want to perform this democratic vote ;) Hope this answer to your question. Corentin On Tue, Oct 26, 2010 at 7:17 PM, Christopher Done chrisd...@googlemail.comwrote: On 26 October 2010 18:07, Dupont Corentin corentin.dup...@gmail.com wrote: But how can I write the evaluator for Map? Where do values for PlayerNumber come from? Unless I'm mistaken, the only thing that Map can be used with is Obs [PlayerNumber], a list of values PlayerNumber which we have no means of acquiring in order to provide to the Map function. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Manual Type-Checking to provide Read instances for GADTs. (was Re: [Haskell-cafe] Read instance for GATD)
That's really nice. Very interesting. Thank you. On Fri, Jun 25, 2010 at 9:55 PM, Edward Kmett ekm...@gmail.com wrote: I've obtained permission to repost Gershom's slides on how to deserialize GADTs by typechecking them yourself, which are actually a literate haskell source file, that he was rendering to slides. Consequently, I've just pasted the content below as a literate email. -Edward Kmett - Deserializing strongly typed values (four easy pieces about typechecking) Gershom Bazerman - prior art: Oleg (of course) http://okmij.org/ftp/tagless-final/course/course.html ...but also Stephanie Weirich http://www.comlab.ox.ac.uk/projects/gip/school/tc.hs = Ahem... \begin{code} {-# LANGUAGE DeriveDataTypeable, ExistentialQuantification, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, RankNTypes, ScopedTypeVariables #-} \end{code} = ahem. \begin{code} import Data.Typeable import Data.Maybe import Control.Monad.Error import Control.Applicative import qualified Data.Map as M import Unsafe.Coerce \end{code} = A simple ADT. \begin{code} data SimpleExpr = SOpBi String SimpleExpr SimpleExpr | SOpUn String SimpleExpr | SDbl Double | SBool Bool deriving (Read, Show, Typeable) \end{code} Yawn. = An awesome GADT! \begin{code} data Expr a where EDbl :: Double - Expr Double EBool :: Bool - Expr Bool EBoolOpBi :: BoolOpBi - Expr Bool - Expr Bool - Expr Bool ENumOpBi :: NumOpBi - Expr Double - Expr Double - Expr Double ENumOpUn :: NumOpUn - Expr Double - Expr Double deriving Typeable data NumOpBi = Add | Sub deriving (Eq, Show) data NumOpUn = Log | Exp deriving (Eq, Show) data BoolOpBi = And | Or deriving (Eq, Show) \end{code} The GADT is well typed. It cannot go wrong. - It also cannot derive show. = But we can write show... \begin{code} showIt :: Expr a - String showIt (EDbl d) = show d showIt (EBool b) = show b showIt (EBoolOpBi op x y) = ( ++ show op ++ ++ showIt x ++ ++ showIt y ++ ) showIt (ENumOpBi op x y) = ( ++ show op ++ ++ showIt x ++ ++ showIt y ++ ) showIt (ENumOpUn op x) = show op ++ ( ++ showIt x ++ ) \end{code} = And eval is *much nicer*. It cannot go wrong -- no runtime typechecks. \begin{code} evalIt :: Expr a - a evalIt (EDbl x) = x evalIt (EBool x) = x evalIt (EBoolOpBi op expr1 expr2) | op == And = evalIt expr1 evalIt expr2 | op == Or = evalIt expr2 || evalIt expr2 evalIt (ENumOpBi op expr1 expr2) | op == Add = evalIt expr1 + evalIt expr2 | op == Sub = evalIt expr1 - evalIt expr2 \end{code} = But how do we write read!? read EBool False = Expr Bool read EDbl 12 = Expr Double The type being read depends on the content of the string. Even worse, we want to read not from a string that looks obvious to Haskell (i.e. a standard showlike instance) but from something that looks pretty to the user -- we want to *parse*. So we parse into our simple ADT. Then we turn our simple ADT into our nice GADT. - But how? How do we go from untyped... to typed? [And in general -- not just into an arbitrary GADT, but an arbitrary inhabitant of a typeclass.] [i.e. tagless final, etc] = Take 1: Even if we do not know what type we are creating, we eventually will do something with it. So we paramaterize our typechecking function over an arbitrary continuation. \begin{code} mkExpr :: (forall a. (Show a, Typeable a) = Expr a - r) - SimpleExpr - r mkExpr k expr = case expr of SDbl d - k $ EDbl d SBool b - k $ EBool b SOpUn op expr1 - case op of log - k $ mkExpr' (ENumOpUn Log) expr1 exp - k $ mkExpr' (ENumOpUn Exp) expr1 _ - error bad unary op SOpBi op expr1 expr2 - case op of add - k $ mkExprBi (ENumOpBi Add) expr1 expr2 sub - k $ mkExprBi (ENumOpBi Sub) expr1 expr2 \end{code} = Where's the typechecking? \begin{code} mkExpr' k expr = mkExpr (appCast $ k) expr mkExprBi k expr1 expr2 = mkExpr' (mkExpr' k expr1) expr2 appCast :: forall a b c r. (Typeable a, Typeable b) = (c a - r) - c b - r appCast f x = maybe err f $ gcast x where err = error $ Type error. Expected: ++ show (typeOf (undefined::a)) ++ , Inferred: ++ show (typeOf (undefined::b)) \end{code} ... We let Haskell do all the work! = Hmmm... the continuation can be anything. So let's just make it an existential constructor. \begin{code} data ExprBox = forall a. Typeable a = ExprBox (Expr a) appExprBox :: (forall a. Expr a - res) - ExprBox - res
Re: [Haskell-cafe] Re: GATD and pattern matching
Thanks all, it works fine (see below). I lamentably try to make the same for show: showTypeable :: (Typeable a) = a - String showTypeable x = case cast x of Just x' - show x' Nothing - Because it really upsets me to add this show constraints to the Equ constructor ;) what if i want to make an Obs instance with non showable elements, with no intention to show it of course? Corentin instance Typeable1 Obs where typeOf1 _ = mkTyConApp (mkTyCon Obs) [] (===) :: (Typeable a, Typeable b, Eq b) = a - b - Bool (===) x y = cast x == Just y data Obs a where Player :: Obs Player Official :: Obs Bool Equ :: (Eq a, Show a, Typeable a) = Obs a - Obs a - Obs Bool Plus :: (Num a) = Obs a - Obs a - Obs a Time :: (Num a) = Obs a - Obs a - Obs a Minus:: (Num a) = Obs a - Obs a - Obs a And :: Obs Bool - Obs Bool - Obs Bool Or :: Obs Bool - Obs Bool - Obs Bool Not :: Obs Bool - Obs Bool Konst:: (Show a, Eq a) = a - Obs a instance Show t = Show (Obs t) where show Player = Player show Official= Official show (Equ a b) = (show a) ++ Eq ++ (show b) show (Plus a b) = (show a) ++ Plus ++ (show b) show (Minus a b) = (show a) ++ Minus ++ (show b) show (Time a b) = (show a) ++ Time ++ (show b) show (Konst a) = (Konst ++ (show a) ++ ) show (And a b) = (show a) ++ And ++ (show b) show (Or a b)= (show a) ++ Or ++ (show b) show (Not a) = (Not ++ (show a) ++ ) instance Eq t = Eq (Obs t) where Player == Player = True Official == Official = True Equ a b == Equ c d = (a,b) === (c,d) Plus a b == Plus c d = (a == c) (b == d) Minus a b == Minus c d = (a == c) (b == d) Time a b == Time c d = (a == c) (b == d) And a b == And c d = (a == c) (b == d) Or a b == Or c d = (a == c) (b == d) Not a == Not b = (a == b) Konst a == Konst b = a == b _ == _ = False ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: GATD and pattern matching
On Thu, Jun 10, 2010 at 11:14 PM, Daniel Fischer daniel.is.fisc...@web.dewrote: On Thursday 10 June 2010 22:01:38, Dupont Corentin wrote: Hello Maciej, i tried this out, but it didn't worked. Daniel, I added a (Show a) constraint to Equal: data Obs a where Player :: Obs Integer Turn :: Obs Integer Official :: Obs Bool Equ :: (Show a, Eq a) = Obs a - Obs a - Obs Bool --woops!! Plus :: (Num a) = Obs a - Obs a - Obs a Time :: (Num a) = Obs a - Obs a - Obs a Minus :: (Num a) = Obs a - Obs a - Obs a Konst :: a - Obs a And :: Obs Bool - Obs Bool - Obs Bool Or :: Obs Bool - Obs Bool - Obs Bool It works for the Show instance, but not Eq. By the way, shouldn't the Show constraint be on the instance and not on the datatype declaration? Can't be here, because of Equ :: Obs a - Obs a - Obs Bool You forget the parameter a, and you can't recover it in the instance declaration. So you have to provide the Show instance for a on construction, i.e. put the constraint on the data constructor. Anyway, is my Obs construction revelant at all? What i want to do is to provide an EDSL to the user to test things about the state of the game (for the Nomic game i'm making). Obs will be then embedded in another EDSL to construct Nomic's rules. I'd prefer to keep the datatype as generic as possible... There is really no way to make my Obs datatype an instance of Eq and Show?? Show can work (should with the constraint on Equ), Eq is hairy. instance Show t = Show (Obs t) where show (Equ a b) = show a ++ `Equal` ++ show b show (Plus a b) = ... show (Konst x) = Konst ++ show x ... For an Eq instance, you have the problem that Equ (Konst True) (Konst False) and Equ Player Turn both have the type Obs Bool, but have been constructed from different types, so you can't compare (Konst True) and Player. I don't see a nice way to work around that. These is a dirty way: compare the string representation of the rules. They should be unique. Corentin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: GATD and pattern matching
Hello Maciej, i tried this out, but it didn't worked. Daniel, I added a (Show a) constraint to Equal: data Obs a where Player :: Obs Integer Turn :: Obs Integer Official :: Obs Bool Equ :: (Show a, Eq a) = Obs a - Obs a - Obs Bool --woops!! Plus :: (Num a) = Obs a - Obs a - Obs a Time :: (Num a) = Obs a - Obs a - Obs a Minus :: (Num a) = Obs a - Obs a - Obs a Konst :: a - Obs a And :: Obs Bool - Obs Bool - Obs Bool Or :: Obs Bool - Obs Bool - Obs Bool It works for the Show instance, but not Eq. By the way, shouldn't the Show constraint be on the instance and not on the datatype declaration? I'd prefer to keep the datatype as generic as possible... There is really no way to make my Obs datatype an instance of Eq and Show?? I searched around a way to add type information on the pattern match like: instance Show t = Show (Obs t) where show (Equal (a::Obs t) (b::Obs t)) = (show a) ++ Equal ++ (show b) show (Plus a b) = (show a) ++ Plus ++ (show b) But it doesn't work. thanks for your help, Corentin On Thu, Jun 10, 2010 at 2:47 AM, Maciej Piechotka uzytkown...@gmail.comwrote: On Wed, 2010-06-09 at 22:28 +0200, Dupont Corentin wrote: Thanks for your response. How would you do it? I design this GATD for a game i'm making: data Obs a where Player :: Obs Integer Turn :: Obs Integer Official :: Obs Bool Equ :: Obs a - Obs a - Obs Bool --woops!! Plus :: (Num a) = Obs a - Obs a - Obs a Time :: (Num a) = Obs a - Obs a - Obs a Minus :: (Num a) = Obs a - Obs a - Obs a Konst :: a - Obs a Actually woops is here. Make it for example Const :: (Show a, Eq a, ...) = a - Obs a And :: Obs Bool - Obs Bool - Obs Bool Or :: Obs Bool - Obs Bool - Obs Bool For example I can design an Observable like that: myObs = Player `Equ` (Konst 1) `And` Official These Observables will then be processed during gameplay. I would like to be able to do in ghci: show myObs Player `Equ` (Konst 1) `And` Official and: myObs == myObs True Regards ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] A Finally Tagless Pi Calculus
Hello, I am making a little GATD: {-# LANGUAGE GADTs#-} data Obs a where Equal :: Obs a - Obs a - Obs Bool Plus :: (Num a) = Obs a - Obs a - Obs a (etc..) instance Show t = Show (Obs t) where show (Equal a b) = (show a) ++ Equal ++ (show b) show (Plus a b) = (show a) ++ Plus ++ (show b) instance Eq t = Eq (Obs t) where a `Equal` b == c `Equal` d = (a == c) (b == d) a `Plus` b == c `Plus` d = (a == c) (b == d) The Equal constructor causes me problems, while the Plus is fine: test3.lhs:8:26: Could not deduce (Show a) from the context (t ~ Bool) arising from a use of `show' at test3.lhs:8:26-31 Possible fix: add (Show a) to the context of the constructor `Equal' In the first argument of `(++)', namely `(show a)' In the expression: (show a) ++ Equal ++ (show b) In the definition of `show': show (Equal a b) = (show a) ++ Equal ++ (show b) I guess this is because GADT refines type with pattern matching. Since Equal return type is Obs Bool and not Obs a, it cannot bind the type variable a to belong to Show. I don't see how to precise the type in the pattern match. I have another problem: test3.lhs:12:41: Couldn't match expected type `a' against inferred type `a1' `a' is a rigid type variable bound by the constructor `Equal' at test3.lhs:12:8 `a1' is a rigid type variable bound by the constructor `Equal' at test3.lhs:12:23 Expected type: Obs a Inferred type: Obs a1 In the second argument of `(==)', namely `c' In the first argument of `()', namely `(a == c)' Cheers, Corentin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] GATD and pattern matching
Hello, I am making a little GATD: {-# LANGUAGE GADTs#-} data Obs a where Equal :: Obs a - Obs a - Obs Bool Plus :: (Num a) = Obs a - Obs a - Obs a (etc..) instance Show t = Show (Obs t) where show (Equal a b) = (show a) ++ Equal ++ (show b) show (Plus a b) = (show a) ++ Plus ++ (show b) instance Eq t = Eq (Obs t) where a `Equal` b == c `Equal` d = (a == c) (b == d) a `Plus` b == c `Plus` d = (a == c) (b == d) The Equal constructor causes me problems, while the Plus is fine: test3.lhs:8:26: Could not deduce (Show a) from the context (t ~ Bool) arising from a use of `show' at test3.lhs:8:26-31 Possible fix: add (Show a) to the context of the constructor `Equal' In the first argument of `(++)', namely `(show a)' In the expression: (show a) ++ Equal ++ (show b) In the definition of `show': show (Equal a b) = (show a) ++ Equal ++ (show b) I guess this is because GADT refines type with pattern matching. Since Equal return type is Obs Bool and not Obs a, it cannot bind the type variable a to belong to Show. I don't see how to precise the type in the pattern match. I have another problem: test3.lhs:12:41: Couldn't match expected type `a' against inferred type `a1' `a' is a rigid type variable bound by the constructor `Equal' at test3.lhs:12:8 `a1' is a rigid type variable bound by the constructor `Equal' at test3.lhs:12:23 Expected type: Obs a Inferred type: Obs a1 In the second argument of `(==)', namely `c' In the first argument of `()', namely `(a == c)' Cheers, Corentin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] GATD and pattern matching
Thanks for your response. How would you do it? I design this GATD for a game i'm making: data Obs a where Player :: Obs Integer Turn :: Obs Integer Official :: Obs Bool Equ :: Obs a - Obs a - Obs Bool --woops!! Plus :: (Num a) = Obs a - Obs a - Obs a Time :: (Num a) = Obs a - Obs a - Obs a Minus :: (Num a) = Obs a - Obs a - Obs a Konst :: a - Obs a And :: Obs Bool - Obs Bool - Obs Bool Or :: Obs Bool - Obs Bool - Obs Bool For example I can design an Observable like that: myObs = Player `Equ` (Konst 1) `And` Official These Observables will then be processed during gameplay. I would like to be able to do in ghci: show myObs Player `Equ` (Konst 1) `And` Official and: myObs == myObs True Corentin On Wed, Jun 9, 2010 at 9:10 PM, Daniel Fischer daniel.is.fisc...@web.dewrote: On Wednesday 09 June 2010 20:37:22, Dupont Corentin wrote: Hello, I am making a little GATD: {-# LANGUAGE GADTs#-} data Obs a where Equal :: Obs a - Obs a - Obs Bool Plus :: (Num a) = Obs a - Obs a - Obs a (etc..) instance Show t = Show (Obs t) where show (Equal a b) = (show a) ++ Equal ++ (show b) show (Plus a b) = (show a) ++ Plus ++ (show b) instance Eq t = Eq (Obs t) where a `Equal` b == c `Equal` d = (a == c) (b == d) a `Plus` b == c `Plus` d = (a == c) (b == d) The Equal constructor causes me problems, while the Plus is fine: test3.lhs:8:26: Could not deduce (Show a) from the context (t ~ Bool) arising from a use of `show' at test3.lhs:8:26-31 Possible fix: add (Show a) to the context of the constructor `Equal' In the first argument of `(++)', namely `(show a)' In the expression: (show a) ++ Equal ++ (show b) In the definition of `show': show (Equal a b) = (show a) ++ Equal ++ (show b) I guess this is because GADT refines type with pattern matching. Since Equal return type is Obs Bool and not Obs a, it cannot bind the type variable a to belong to Show. Right. You can have (+ 3) `Equal` sin :: Obs Bool , but how would you show it? You could add a (Show a) constraint to Equal. I don't see how to precise the type in the pattern match. I have another problem: test3.lhs:12:41: Couldn't match expected type `a' against inferred type `a1' `a' is a rigid type variable bound by the constructor `Equal' at test3.lhs:12:8 `a1' is a rigid type variable bound by the constructor `Equal' at test3.lhs:12:23 Expected type: Obs a Inferred type: Obs a1 In the second argument of `(==)', namely `c' In the first argument of `()', namely `(a == c)' ((+ 3) `Equal` sin) == (True `Equal` False) Doesn't work. And you can't make it work, because in (a `Equal` b) == (c `Equal` d) , a and b have the same type t1, and c and d have the same type t2 but the two types t1 and t2 are generally different, so calling (==) on a and c has no chance to type-check. With Equal forgetting the type parameter of its arguments, I don't think it's possible. Cheers, Corentin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] accents
Thank you Daniel and Ivan, with firefox i finded out that my text file was encoded in WINDOWS-1252. So a commande line such as: iconv -f WINDOWS-1252 -t ISO-8859-1 liste.txt liste2.txt did the trick. Alternatively, i modified my code with: myReadFile a = do h - openFile a ReadMode te - mkTextEncoding CP1252 hSetEncoding h te hGetContents h Corentin On 5/7/10, Daniel Fischer daniel.is.fisc...@web.de wrote: On Friday 07 May 2010 17:05:08 you wrote: I don't know the encoding of my file, how to deduce it? What happens if you open it in a text editor? When it looks right, can you find out from the editor what encoding it used? You could try opening the file in Firefox (or some other browser), go to View - Character Encoding and see what it thinks it is (click Auto-Detect if you have selected some default encoding) if it looks right. If it looks garbled, try selecting different encodings to see if one looks right. You could send me [a part of] the file and I could try and find something out (play a little with iconv). ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] accents
Hello, i'm still struggling with ghci and accents. Prelude é \233 I've installed GHC 6.12.1, which gave me a better result: Prelude putStrLn é é but still: Prelude é \233 I'm trying to search a file with french words with Regex, but i stumble on accents: *Main findRegexFile abnégation [] *Main findRegexFile abn.gation [abn\218gation,abn\218gations] I don't know the encoding of my file, how to deduce it? What is the encoding used by ghci? Unicode? Its seems not be the same since the représentation for é is not the same (\233 and \218). How to have accented characters in ghci? Can't find any ressources on the net. Cheers, Corentin PS: please let me know is you can't see the accented characters in this email, i'll send you another version with pictures. On 3/24/10, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: Dupont Corentin corentin.dup...@gmail.com writes: a - readFile list.txt head $ lines a abn\233gation putStrLn displays a strange character for the é. That is the escaped form of é. You have several options: 1) Use the utf8-string package for I/O 2) Use the text package for I/O (and set an encoding) 3) GHC 6.12.1 uses the system's locale for encoding; as such if your system normally lets you see accented characters then putStrLn, etc. will print them out. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Type system game (was: Nomic game in Haskell)
Hello, I think your type should be: type Board a b c d e f g h i = Either (Three a b c) (Either (Three d e f) (Either (Three g h i) (Either (Three a d g) (Either (Three b e h) (Either (Three c f i) (Either (Three a e i) (Three c e g))) as far as i can understand, it seems thats it's mandatory for Player 1 to play in a,b,c to win? So victory should go to player 2? Cheers, Corentin On 4/16/10, Dan Piponi dpip...@gmail.com wrote: On Thu, Apr 15, 2010 at 4:58 PM, Ashley Yakeley ash...@semantic.org wrote: type Board a b c d e f g h i = Either (Three a b c) (Either (Three d e f) (Either (Three g h i) (Either (Three a d g) (Either (Three b e h) (Either (Three c f i) (Either (Three a e i) (Either (Three c e g) ))) In the service of readability we could also define: data X = X data O Though the victory conditions aren't precisely the usual ones. -- Dan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Nomic game in Haskell
Yes indeed, Nomic couldn't be fully coded, only a subset of it could be. Rules that are outside of the box cannot be expressed, the goal is, to have the largest box possible! Your rule: * Players must stand when proposing new rules. couldn't be coded directly, of course, since the computer has no sensor to detect the position of player ;) But it could be indirectly. Your rule could be coded like that: Full rule tiltle: Players must stand when proposing new rules Code when filtering a proposed rule: A question is asked to all players except the author of the rule: Does Player X stood when he proposed this rule? A vast majority of Yes must be acknowlegded to accept the rule. On the other hand, if we choose not to interpret the rules, the program could just be a configuration management system for rules. It could be a web site that maintain active rules, allow player voting etc. Corentin. On 4/15/10, Brent Yorgey byor...@seas.upenn.edu wrote: On Wed, Apr 14, 2010 at 09:14:18PM +0200, Dupont Corentin wrote: Hello Café, do you know Nomic? It's a fabulous and strange game where you have the right to change the rules in the middle of the game! In fact, changing the rules is the goal of the game. Changing a rule is considered as a move. Of course even that could be changed! www.nomic.net I'm wondering if it could be possible to implement a Nomic (or an helper for the game) in Haskell. Haskell seems appropriate for that, since functions are first order objects, and Haskell is good at DSLs. I don't think you could actually implement Nomic in the way you describe, because any system you come up with will necessarily place restrictions on what sorts of rules you are able to represent. Much of the fun of Nomic lies in coming up with new rules that are completely outside the box. For example, how would you encode a rule like * Players must stand when proposing new rules. or * Rules which do not mention other rules shall remain in effect until such time as the mobile telephone of the Grand Counselor rings. You get the idea. However, implementing some sort of system for encoding certain types of rules, and checking that they are valid/consistent/etc. sounds like it could be a fun project from which you would probably learn a lot! Essentially, you would be designing a syntax for rules, and a type system for ensuring that rules are valid or used in valid ways. It wouldn't be Nomic, but it could be something fun. -Brent ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Nomic game in Haskell
Hello Café, do you know Nomic? It's a fabulous and strange game where you have the right to change the rules in the middle of the game! In fact, changing the rules is the goal of the game. Changing a rule is considered as a move. Of course even that could be changed! www.nomic.net I'm wondering if it could be possible to implement a Nomic (or an helper for the game) in Haskell. Haskell seems appropriate for that, since functions are first order objects, and Haskell is good at DSLs. What I think, is creating a DSL where a rule could be expressed as a function, or a monad. Many kinds of rules could be expressed: 1. - a rule that says that player #1 must be named Grand Counselor. 2. - a rule that says that the following rules must be voted at the majority, and how. 3. - a rule that says that the money is the ECU. 4. - a rule that says that if a rule is accepted, the author is awarded 1 ECU. 5. - a rule that says that all rules must have a name. 6. - a rule that says that democracy is abolished. God save the King, Player #1! 7. - a rule that says that a rule mustn't suppress another. As you can see, the rules are highly self-referencing! some rules, like #1, describes a protocol, involving IO (players voting). some rules, like #7, could be implemented with a test over new rules (that rule could test proposed rules against rule suppression). some rules, like #5, must inspect the code of other rules. A proposed rule must pass all active rule's criterias to become active. Once active, a rule should be applyed immediatly to all active rules, and to all futur rules, until it is repealed. Any comments? Cheers, Corentin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] cabal through PHPProxy
Hello, i'm using PHPProxy to go on the internet (www.phpproxy.fr). How can i tell cabal to use this? Cheers, Corentin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] cabal through PHPProxy
Thanks for the response. I don't think this will work because PHPProxy is a web based proxy. To use it, you have to type the http address you want in a field on the page. Corentin On 3/31/10, Bayley, Alistair alistair.bay...@invesco.com wrote: From: haskell-cafe-boun...@haskell.org [mailto:haskell-cafe-boun...@haskell.org] On Behalf Of Dupont Corentin i'm using PHPProxy to go on the internet (www.phpproxy.fr). How can i tell cabal to use this? I think the normal way is through setting HTTP_PROXY env var e.g. set HTTP_PROXY=http://localhost:3128 (I have a cntlm proxy on my local machine because our corporate proxy uses NTLM authentication, which cabal does not support.) Alistair * Confidentiality Note: The information contained in this message, and any attachments, may contain confidential and/or privileged material. It is intended solely for the person(s) or entity to which it is addressed. Any review, retransmission, dissemination, or taking of any action in reliance upon this information by persons or entities other than the intended recipient(s) is prohibited. If you received this in error, please contact the sender and delete the material from any computer. * ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] phonetic dictionnary
Hello, sorry if i ask a lot of questions these days! Do you know of a phonetic dictionnary? i'm very fond of enigmas. To solve certain enigmas, i've made a little program that search into a french dictionnary. But it would be much better if i could search into a phonetic dictionnary... The goal is to answer questions like Wich word would rhyme with aligator? Corentin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] phonetic dictionnary
Hello, i've allready looked at soundex. But it's too simple for what i need. For example the hash code for toto and tata is the same, if i remember. But those two doesn't rhymes. Co On 3/25/10, Paul Brauner paul.brau...@loria.fr wrote: You should have a looks at soundexes: http://en.wikipedia.org/wiki/Soundex the algorithm is really simple and you can process a whole dictionnary in no time to obtain what you're looking for. Paul On Thu, Mar 25, 2010 at 01:59:28PM +0100, Dupont Corentin wrote: Hello, sorry if i ask a lot of questions these days! Do you know of a phonetic dictionnary? i'm very fond of enigmas. To solve certain enigmas, i've made a little program that search into a french dictionnary. But it would be much better if i could search into a phonetic dictionnary... The goal is to answer questions like Wich word would rhyme with aligator? Corentin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] phonetic dictionnary
Thanks, this dictionnary is exactly what i wanted! Too bad it doesn't exists in French! On 3/25/10, Max Rabkin max.rab...@gmail.com wrote: There is the CMU phonetic dictionary for English at http://www.speech.cs.cmu.edu/cgi-bin/cmudict but I know of nothing for French. Perhaps there is an open-source text-to-speech engine that has a free French pronouncing dictionary. --Max On Thu, Mar 25, 2010 at 2:59 PM, Dupont Corentin corentin.dup...@gmail.com wrote: Hello, sorry if i ask a lot of questions these days! Do you know of a phonetic dictionnary? i'm very fond of enigmas. To solve certain enigmas, i've made a little program that search into a french dictionnary. But it would be much better if i could search into a phonetic dictionnary... The goal is to answer questions like Wich word would rhyme with aligator? Corentin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] accents
Hello, i have a list of french words with accents. How could i handle them? If i load them with ghci i get: a - readFile list.txt head $ lines a abn\233gation putStrLn displays a strange character for the é. Cheers, Corentin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Graphical representation of Haskell code
Hello, Very interresting. Visual Haskell seems to be very close to the thing i imagined. Mihai what do you think? Unfortunatly i cannot find it on the web! There is something for MS Visual Studio but i don't think this is the same... Corentin On Thu, Mar 25, 2010 at 12:07 AM, Miguel Vilaca jmvil...@di.uminho.ptwrote: Hi all, Concerning INblobs, it's again online; a fire damaged the cable that links the university to the world!! I don't update the tool for a long time... but I'll take a look on that. Concerning visual functional programming, see this small chapter of my thesis about some of the existing languages. There are more subtleties on the visual side than those expected!! If you also consider debugging tools, take a look on Ghood http://hackage.haskell.org/package/GHood best regards Miguel Vilaça A 2010/03/23, às 05:31, Ronald Guida escreveu: On Mon, Mar 22, 2010 at 7:02 PM, Dupont Corentin corentin.dup...@gmail.com wrote: Hello, I’m relatively new to Haskell. I’m wondering if it exist a tool to graphically represent Haskell code. ... Let’s try to do it on a simple example, as an exercise: f = Map (+1) Your graphic for f = map (+1) seems much more complex than the corresponding code. I would agree with Ivan Miljenovic: I'm of the opinion that unless you just use it on small snippets, the generated images will be too large and unwieldy. The first question I would ask is /why/ would you like to visualize some Haskell code? If you want to see the high-level structure of a complex program, try SourceGraph. (I have never used it though.) On the other hand, if you are trying to visualize Haskell as part of your efforts to learn the language, then I believe it would be best to draw diagrams by hand, rather than relying on an automated tool. The kinds of things that you'll want to depict are probably going to vary considerably, depending on what you're trying to understand. Consider a few different implementations of the map function: -- version 1: recursion map1 :: (a - b) - [a] - [b] map1 f [] = [] map1 f (x:xs) = (f x) : map1 f xs -- version 2: fold map2 :: (a - b) - [a] - [b] map2 f = foldr ((:) . f) [] -- version 3: continuation passing style map3 :: (a - b) - [a] - [b] map3 f xs = map' (\x y - f x : y) xs where map' k [] = [] map' k (y:ys) = k y (map' k ys) -- version 4: list comprehension map4 :: (a - b) - [a] - [b] map4 f xs = [f x | x - xs] -- version 5: list monad map5 :: (a - b) - [a] - [b] map5 f xs = xs = (return . f) These all do exactly the same thing, but each one uses different techniques. If I'm trying to learn (or teach) Haskell, I would probably need a slightly different visual language for each one in order to capture the most relevant concepts in a useful way. How would you visualize them? @Mihai Maruseac: I think a visual debugger would be a wonderful idea. You may want to consider how a visual debugger would work with each of these versions of map. :-) You might also consider several versions of factorial :-) http://www.willamette.edu/~fruehr/haskell/evolution.htmlhttp://www.willamette.edu/%7Efruehr/haskell/evolution.html -- Ron ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Graphical representation of Haskell code
Hello! Thanks for the welcome! Ivan: Too overcome the problem of large and messy images, i propose too have a system to navigate into the code. You could zoom in and out, occulting unecessary details while zooming out. My big graphic of map (+1) could easely be summed up to: (Embedded image moved to file: pic36782.jpg) My idea is to provide an efficient system of zooming, as you can zoom in a fractal picture, showing more or less details! Such a tool, if created, could be implemented as a part of, or used by SourceGraph. In the first place i thought the GHC API would be great to infer each function's type. But indeed haskell-src-exts seems to be more appropriate as you get the structure of the program. Lyndon: Wahou this page (MockingBirds) his very interresting and funny! Mihai: That's funny we had the same idea quite the same time. I guess that idea is in the air and as said one contributor on your Reddit, a well explored territory: It has major pitfalls and the reason why we heard little about that wild territory is because many explorers never returned :) By the way, i'm interrested and i could contribute on the little spare time i have. My idea is to make it as a library that display code as graphs. That library could be used for several purposes: debugging as you proposes, but also education, shows, audit (with SourceGraph), and why not construction... I think this kind of visual tool could be a plus in Haskell popularity. Despite not being that efficient, it is spectacular. Ronald: I agree big graphs are confusing. The big point of the project is to find or adapt an algorithm to simplify the graph and make it valuable. I'll have to make little graphics for each of your versions of map, this may be instructive to me... Stephen: I'll have a look at those interaction nets! But the home page for INBlobs seems to be down. Thank you all for you kind responses. Corentin attachment: pic36782.jpg___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Graphical representation of Haskell code
Hello, I’m relatively new to Haskell. I’m wondering if it exist a tool to graphically represent Haskell code. Look at the little graphics at: http://www.haskell.org/arrows/index.html (and following pages) from Ross Paterson. http://www.haskell.org/arrows/index.htm If found these very useful to understand the Arrow monad. Why not automatise this in a tool? Such a tool could draw a graphic from the code of a program. This could be done entirely automatically from the types of the functions. Let’s try to do it on a simple example, as an exercise: f = Map (+1) How does this function could be represented? It contains the (+) function. This function has the type (+) :: Num a = a - a - a. From this type we could deduce the graphic: [image: Haskell schematic_html_m20060f13.gif] Or a curried version: [image: Haskell schematic_html_5155f0eb.gif] The function (+1) then is: [image: Haskell schematic_html_m68795eb7.gif] The function map could be drawn like this : [image: Haskell schematic_html_m28c92a58.gif] Or like this: [image: Haskell schematic_html_m6ae433ea.gif] And the entire function map (+1) could be represented as: [image: Haskell schematic_html_macb1643.gif] Thanks to the advanced type system of Haskell, everything could be deduced from the type signatures. Such a tool would be recreational and educational. One could zoom in and out in a program, to display more or less details. This could help understand a program, globally or locally. We could even imagine a constructive version of the tool, where the programmer would draw functions from a toolbox, and stick them into the graphic! Does a tool approaching this already exist? If not, would it be a good project? Cheers, Corentin Haskell schematic_html_m28c92a58.gifHaskell schematic_html_m6ae433ea.gifHaskell schematic_html_m68795eb7.gifHaskell schematic_html_macb1643.gifHaskell schematic_html_m20060f13.gifHaskell schematic_html_5155f0eb.gif___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] games of chance
Thanks a lot Mark. Corentin On Sat, Feb 20, 2010 at 4:26 AM, Mark Wassell mwass...@bigpond.net.auwrote: Take a look at: http://hackage.haskell.org/package/probability and http://web.engr.oregonstate.edu/~erwig/pfp/http://web.engr.oregonstate.edu/%7Eerwig/pfp/ Mark Dupont Corentin wrote: Hello, are you aware of a framework to find probabilities in a given game of chance, in Haskell? l would like to compute probabilities like: roll 3 dices, sum the result, then roll 3 other dices, sum the result, what is the probability to obtain the same sum? Cheers, Corentin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] games of chance
Hello, are you aware of a framework to find probabilities in a given game of chance, in Haskell? l would like to compute probabilities like: roll 3 dices, sum the result, then roll 3 other dices, sum the result, what is the probability to obtain the same sum? Cheers, Corentin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe