[Haskell-cafe] Type problem
Why? Shouldn't this work for any type a? Michael == f :: [a] - [a] f l = do x - l return x == *Main :r [1 of 1] Compiling Main ( test.hs, interpreted ) Ok, modules loaded: Main. *Main f abcde abcde *Main f [1,2,3,4,5] [1,2,3,4,5] *Main abcde = f interactive:1:12: Couldn't match expected type `Char' against inferred type `m b' In the second argument of `(=)', namely `f' In the expression: abcde = f In the definition of `it': it = abcde = f *Main ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Type problem
Because applying f to the list is not the same thing is applying bind to the list and f. Bob On 26 Feb 2011, at 20:17, michael rice wrote: Why? Shouldn't this work for any type a? Michael == f :: [a] - [a] f l = do x - l return x == *Main :r [1 of 1] Compiling Main ( test.hs, interpreted ) Ok, modules loaded: Main. *Main f abcde abcde *Main f [1,2,3,4,5] [1,2,3,4,5] *Main abcde = f interactive:1:12: Couldn't match expected type `Char' against inferred type `m b' In the second argument of `(=)', namely `f' In the expression: abcde = f In the definition of `it': it = abcde = f *Main ___ 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] Type problem
Does this help? listbind :: [a] - (a - [b]) - [b] listbind = (=) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Type problem
Yeah, my bad. Thanks. Michael --- On Sat, 2/26/11, Stephen Tetley stephen.tet...@gmail.com wrote: From: Stephen Tetley stephen.tet...@gmail.com Subject: Re: [Haskell-cafe] Type problem To: Cc: haskell-cafe@haskell.org Date: Saturday, February 26, 2011, 3:24 PM Does this help? listbind :: [a] - (a - [b]) - [b] listbind = (=) ___ 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] How to fix such a TYPE problem ?
let [y,m,d] = map (\x - read x::Int) $ splitRegex (mkRegex -) 2009-08-31 fromGregorian y m d Couldn't match expected type `Integer' against inferred type `Int' In the first argument of `fromGregorian', namely `y' In the expression: fromGregorian y m d In the definition of `it': it = fromGregorian y m d thanks! -- View this message in context: http://www.nabble.com/How-to-fix-such-a-TYPE-problem---tp25233906p25233906.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to fix such a TYPE problem ?
On Mon, Aug 31, 2009 at 9:47 PM, zaxisz_a...@163.com wrote: let [y,m,d] = map (\x - read x::Int) $ splitRegex (mkRegex -) 2009-08-31 fromGregorian y m d Couldn't match expected type `Integer' against inferred type `Int' In the first argument of `fromGregorian', namely `y' In the expression: fromGregorian y m d In the definition of `it': it = fromGregorian y m d fromGregorian is expecting an Integer for y, and you gave it an Int. You just need to convert; fromIntegral works fine for this. fromGregorian (fromIntegral y) m d ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to fix such a TYPE problem ?
thanks! Luke Palmer-2 wrote: On Mon, Aug 31, 2009 at 9:47 PM, zaxisz_a...@163.com wrote: let [y,m,d] = map (\x - read x::Int) $ splitRegex (mkRegex -) 2009-08-31 fromGregorian y m d Couldn't match expected type `Integer' against inferred type `Int' In the first argument of `fromGregorian', namely `y' In the expression: fromGregorian y m d In the definition of `it': it = fromGregorian y m d fromGregorian is expecting an Integer for y, and you gave it an Int. You just need to convert; fromIntegral works fine for this. fromGregorian (fromIntegral y) m d ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- View this message in context: http://www.nabble.com/How-to-fix-such-a-TYPE-problem---tp25233906p25234336.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Success with Takusen (was: Type problem with simpletakusen code)
To build a program, you need to do ghc --make db.hs -o db D:\Oracle\Ora92\bin\oci.dll (put the path to your oci.dll here). This compiles your program, and links it with oci.dll to get the Oracle externals resolved. I've been working with Paul on his linking problems, and there's a gotcha for Oracle 10 users. Apparently the folder that contains oci.dll, typically $ORACLE_HOME/bin, can also include hsbase.dll, which has something to do with Heterogeneous Services. Obviously (this being Windows, where filenames are not case sensitive) this clashes with GHC's HSbase.dll; hence linker errors. I'm not sure exactly what the solution should be; one obvious one is to not include Heterogeneous Services in your installation. I'm also not sure if this affects Oracle clients; Paul hinted that he was pointing at a server installation folder, so a standard client installation is likely to be OK. 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
Re: [Haskell-cafe] Success with Takusen (was: Type problem with simpletakusen code)
On 12/20/06, Bayley, Alistair [EMAIL PROTECTED] wrote: To build a program, you need to do ghc --make db.hs -o db D:\Oracle\Ora92\bin\oci.dll (put the path to your oci.dll here). This compiles your program, and links it with oci.dll to get the Oracle externals resolved. I've been working with Paul on his linking problems, and there's a gotcha for Oracle 10 users. Apparently the folder that contains oci.dll, typically $ORACLE_HOME/bin, can also include hsbase.dll, which has something to do with Heterogeneous Services. Obviously (this being Windows, where filenames are not case sensitive) this clashes with GHC's HSbase.dll; hence linker errors. To clarify a little - I believe the issue exists on Oracle 8i, 9i and 10g. It's not so much the version as the options you choose when you install the software. As far as I am able to confirm, a default enterprise edition install includes hsbase.dll. A default client install does not. If you do a custom install, then the relevant option is Heterogeneous Services - but the simplest way to check is just to look for hsbase.dll in the oracle home\bin directory. Alistair - maybe you could add a check in Setup.hs, to see if hsbase.dll is present, and if so, to display a warning? I can sort of see where such a check would occur (in configOracle), but I don't know enough about Cabal to suggest code... Paul. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Success with Takusen (was: Type problem with simple takusen code)
On 12/12/06, Paul Moore [EMAIL PROTECTED] wrote: Should be, but isn't, unfortunately. The Setup.hs file includes some code defining configPG etc, but there's nothing I can see for the user control how it works. Maybe something in the cabal infrastructure handles this, but I've not had time yet to dive into the cabal documentation on the hope of finding something. Just a brief note to let people on the list know that, with a lot of extremely patient help from Alistair Bayley, I have managed to resolve the issues I was having. The fundamental issue I was hitting was that I was treating GHC as an interpreted system, rather than a compiler/linker. I was therefore not thinking about the errors I was seeing as I would if I hit (say) a C link error. To summarise, the following works fine: To install Takusen, make sure that an Oracle home is in your PATH. You don't need PostgreSQL or sqlite. Your Oracle install can be simply a client build - all you need is oci.dll, not the full OCI development package. runhaskell Setup.hs configure runhaskell Setup.hs build runhaskell Setup.hs install That's it, and it works fine. To build a program, you need to do ghc --make db.hs -o db D:\Oracle\Ora92\bin\oci.dll (put the path to your oci.dll here). This compiles your program, and links it with oci.dll to get the Oracle externals resolved. Runhaskell doesn't seem to work, as it tries to link all the DB backends at runtime, regardless of whether you use them. That really is all there is to it. Arguably, the error messages you get when you mess up bits of this aren't too helpful, but if you've ever seen a C++ compilation fail with compile or link errors, you'll know not to expect much here (or at least you should!) GHC is certainly no worse than that. Once again, thanks to Alistair for his patience. Now I'll go off and reproduce my success on a clean environment just to be sure, and then write up what I've learnt for the Wiki and the Takusen readme. Paul. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Type problem with simple takusen code (was: Trivialdatabase access in Haskell)
From: Paul Moore [mailto:[EMAIL PROTECTED] runhaskell db.hs can't load .so/.DLL for: sqlite3 (addDLL: unknown error) This seems odd, as I'm not (intending to be) using sqlite here. If I copy a sqlite3.dll onto my PATH (just to get by, it's quite possible sqlite isn't set up right but I really don't care just now) I get past this, but get runhaskell db.hs interactive: C:\Program Files\Haskell\Takusen-0.6\ghc-6.6/HSTakusen-0.6.o: unknown symbol `_PQconnectdb' ghc.exe: unable to load package `Takusen-0.6' This appears to be caused by ghci/runhaskell wanting to link the entire library at once, rather than just the modules you're using. I don't know if this is a bug or a feaure with ghci; anybody else want to comment? This problem affects both ghci and runhaskell. It does not affect ghc, though. I'm not sure what the best solution is; we might have to do what Krasimir did with HSQL and make each database-specific module a separate package. For now, if you want to use Takusen, you are stuck with ghc (the compiler). This invocation: ghc --make db.hs -o db should make you a working db.exe. I have added a README.txt to the darcs repo, which hopefully provides a lot of this missing information. I haven't added uninstall instructions though :-) 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
Re: [Haskell-cafe] Type problem with simple takusen code (was: Trivialdatabase access in Haskell)
On 12/13/06, Bayley, Alistair [EMAIL PROTECTED] wrote: From: Paul Moore [mailto:[EMAIL PROTECTED] This appears to be caused by ghci/runhaskell wanting to link the entire library at once, rather than just the modules you're using. I don't know if this is a bug or a feaure with ghci; anybody else want to comment? This problem affects both ghci and runhaskell. It does not affect ghc, though. I'm not sure what the best solution is; we might have to do what Krasimir did with HSQL and make each database-specific module a separate package. For now, if you want to use Takusen, you are stuck with ghc (the compiler). This invocation: ghc --make db.hs -o db should make you a working db.exe. Thanks for the explanation - it's no problem using ghc, I was only using runhaskell for (a tiny bit of) convenience. Having said that, I now get ghc --make db.hs -o db [1 of 1] Compiling Main ( db.hs, db.o ) Linking db.exe ... D:\Apps\GHC\gcc-lib\ld.exe: cannot find -lsqlite3 collect2: ld returned 1 exit status This may be because I have a sqlite3.dll in my PATH, but no development libs. Would that make configure think that sqlite is available, but because the build needs the link library, fail at that stage? If so, I may well be heading for a problem with Oracle, as I have the client only installed, so the OCI DLLs are present, but not the headers and lib files. (I've hit this one before, and can get round it, though). I had a look on the sqlite website, but can't find a development libraries download. I'm reluctant to get bogged down in building sqlite, so I'm leaving it there for now. To work around this, I removed sqlite3.exe from my PATH, and set up an oracle directory in my PATH which did include OCI. Then runhaskell Setup.hs configure reported no sqlite, no postgres, and Oracle from where I wanted. I reinstalled Takusen with these options. However, now when I run ghc --make, I get a string of link errors from Oracle stuff (OCIconstants.o). This is serious progress - I'm linking the right stuff this time. I've seen similar issues before, where I tried to use gcc to link to the Oracle-supplied OCI libraries (or at least I think that was it), as Oracle supply MSVC compatible libraries instead. Could this be relevant here? I know ghc uses the gcc linker, so it seems like a possibility. I have added a README.txt to the darcs repo, which hopefully provides a lot of this missing information. I haven't added uninstall instructions though :-) That looks excellent - it would have given me exactly what I needed. Paul. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Type problem with simple takusen code (was: Trivialdatabase access in Haskell)
Having said that, I now get ghc --make db.hs -o db [1 of 1] Compiling Main ( db.hs, db.o ) Linking db.exe ... D:\Apps\GHC\gcc-lib\ld.exe: cannot find -lsqlite3 collect2: ld returned 1 exit status This may be because I have a sqlite3.dll in my PATH, but no development libs. You need to have sqlite3.exe in the same folder as sqlite3.dll. sqlite3.exe is what the installer looks for - if it finds it, then it assumes sqlite3.dll is in the same place. When you built takusen, was this in your path? Check the output from runhaskell Setup.hs configure: this tells you if it finds Sqlite, and if so where it is. This information is then baked into takusen.buildinfo, and that's what's used by ghc for linking when you build your program. You don't need it if you want to use Oracle: just remove it from your path and configure/build/install Takusen. However, now when I run ghc --make, I get a string of link errors from Oracle stuff (OCIconstants.o). This is serious progress - I'm linking the right stuff this time. I've seen similar issues before, where I tried to use gcc to link to the Oracle-supplied OCI libraries (or at least I think that was it), as Oracle supply MSVC compatible libraries instead. Could this be relevant here? I know ghc uses the gcc linker, so it seems like a possibility. Not a problem I've experienced, but then my Oracle client install includes the headers etc. I don't think these are necessary unless you compile -fvia-C, which I don't think is happening (ghc -O results in -fvia-C, though). I use ghc for compilation and linking, and I have no trouble. Can you send me the compiler/linker output? Perhaps best if we take this off-list. Also, what version of Oracle is it? I've developed against 8i, and haven't had a chance to test against later versions. 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] Type problem with simple takusen code (was: Trivial database access in Haskell)
(Wow, it looks like my message has generated quite a bit of traffic! Thanks, guys!) On 12/11/06, Taral [EMAIL PROTECTED] wrote: The magic commands are: runhaskell Setup.lhs configure runhaskell Setup.lhs build runhaskell Setup.lhs install Excellent! Now I'm getting somewhere. I even found the sample code in the takusen documentation. I'm trying to modify the sample code to work with a local database I have, and I'm getting some type errors which mean nothing much to me. The code I have, stored in a file called db.hs and run via runhaskell db.hs is: import Control.Monad.Trans import Database.Oracle.Enumerator import Database.Enumerator query1Iteratee :: (Monad m) = String - IterAct m [String] query1Iteratee a accum = result' (a:accum) main :: IO () main = do withSession (connect USER PASSWORD DB) $ do -- simple query, returning reversed list of rows. r - doQuery (sql select username from all_users) query1Iteratee [] liftIO $ putStrLn $ show r The error I'm getting is db.hs:10:64: Couldn't match expected type `forall mark. DBM mark Session a' against inferred type `a1 b' In the second argument of `($)', namely `do r - doQuery (sql select username from all_users) query1Iteratee [] liftIO $ (putStrLn $ (show r))' In the expression: (withSession (connect USER PASSWORD DB)) $ (do r - doQuery (sql select username from all_users) query1Iteratee [] liftIO $ (putStrLn $ (show r))) In the expression: do (withSession (connect USER PASSWORD DB)) $ (do r - doQuery (sql select username from all_users) query1Iteratee [] liftIO $ (putStrLn $ (show r))) I'm not sure what might be wrong here - or even, for that matter, how to diagnose the problem. To complicate the matter, it's possible that I'm getting a database connection error which I've not got code in to report. (I've no easy way to test that the database connection from Haskell is working, or rather *this* is the easy way :-)) Can anyone offer any pointers? (I take the suggestions about asking on IRC, but I can't get at IRC from here due to firewall issues, so I'll have to stick to email). Paul. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Type problem with simple takusen code (was: Trivial database access in Haskell)
Paul Moore wrote: db.hs:10:64: Couldn't match expected type `forall mark. DBM mark Session a' against inferred type `a1 b' In the second argument of `($)', namely `do r - doQuery (sql select username from all_users) query1Iteratee [] liftIO $ (putStrLn $ (show r))' In the expression: (withSession (connect USER PASSWORD DB)) $ (do r - doQuery (sql select username from all_users) query1Iteratee [] liftIO $ (putStrLn $ (show r))) In the expression: do (withSession (connect USER PASSWORD DB)) $ (do r - doQuery (sql select username from all_users) query1Iteratee [] liftIO $ (putStrLn $ (show r))) I had the same problem... ($) doesn't have the expected semantics with existential types (like forall mark. DBM mark Session a). Some day I will be able to explain why this is so, but in the meantime, if you replace liftIO $ putStrLn $ show r with liftIO (putStrLn (show r)), it should work. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Type problem with simple takusen code (was: Trivialdatabase access in Haskell)
main :: IO () main = do withSession (connect USER PASSWORD DB) $ do -- simple query, returning reversed list of rows. r - doQuery (sql select username from all_users) query1Iteratee [] liftIO $ putStrLn $ show r The error I'm getting is db.hs:10:64: Couldn't match expected type `forall mark. DBM mark Session a' against inferred type `a1 b' In the second argument of `($)', namely `do r - doQuery (sql select username from all_users) ... This is a fault in the example. Try this: -- ($) replaced here with () withSession (connect USER PASSWORD DB) ( do r - doQuery (sql ... liftIO $ putStrLn $ show r --- here should be OK ) ($) doesn't handle higher-ranked types, and overusing it can lead to these kinds of errors. 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
Re: [Haskell-cafe] Type problem with simple takusen code (was: Trivialdatabase access in Haskell)
On 12/12/06, Bayley, Alistair [EMAIL PROTECTED] wrote: ($) doesn't handle higher-ranked types, and overusing it can lead to these kinds of errors. Thanks - not something I'd have ever found on my own. Next one: runhaskell db.hs can't load .so/.DLL for: sqlite3 (addDLL: unknown error) This seems odd, as I'm not (intending to be) using sqlite here. If I copy a sqlite3.dll onto my PATH (just to get by, it's quite possible sqlite isn't set up right but I really don't care just now) I get past this, but get runhaskell db.hs interactive: C:\Program Files\Haskell\Takusen-0.6\ghc-6.6/HSTakusen-0.6.o: unknown symbol `_PQconnectdb' ghc.exe: unable to load package `Takusen-0.6' No chance here - I don't have any sort of PostgreSQL software around. I've no idea how it might have thought I did. Can I somehow force PostgreSQL to be disabled? If I need to rebuild to do so (grumble) then how do I uninstall the current version of takusen (it's not in Add/Remove programs and runhaskell Setup.hs doesn't seem to offer an uninstall option... Thanks again, Paul. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Type problem with simple takusen code (was: Trivialdatabase access in Haskell)
On 12/12/06, Paul Moore [EMAIL PROTECTED] wrote: Can I somehow force PostgreSQL to be disabled? If I need to rebuild to do so (grumble) then how do I uninstall the current version of takusen (it's not in Add/Remove programs and runhaskell Setup.hs doesn't seem to offer an uninstall option... There should be a README or INSTALL file in the original tarball that explains how to do that. I suspect it is a flag you have to pass to runhaskell Setup.lhs configure. -- Taral [EMAIL PROTECTED] You can't prove anything. -- Gödel's Incompetence Theorem ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Type problem with simple takusen code (was: Trivialdatabase access in Haskell)
On 12/12/06, Taral [EMAIL PROTECTED] wrote: On 12/12/06, Paul Moore [EMAIL PROTECTED] wrote: Can I somehow force PostgreSQL to be disabled? If I need to rebuild to do so (grumble) then how do I uninstall the current version of takusen (it's not in Add/Remove programs and runhaskell Setup.hs doesn't seem to offer an uninstall option... There should be a README or INSTALL file in the original tarball that explains how to do that. I suspect it is a flag you have to pass to runhaskell Setup.lhs configure. Should be, but isn't, unfortunately. The Setup.hs file includes some code defining configPG etc, but there's nothing I can see for the user control how it works. Maybe something in the cabal infrastructure handles this, but I've not had time yet to dive into the cabal documentation on the hope of finding something. Paul. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: ambiguous partially defined type problem
Dear Brian, Maarten wrote: Brian Hulley wrote: Alternatively, you could wrap the custom part within the node as in: data Node = forall cust. ICustom cust = Node cust Common getCommon :: Node - Common getCommon (Node cust com) = com Thanks. This really helped. The main thing (I think) that you put the custom part behind an interface. After this I separated the custom and common part of two 'piggy bagged' state transformers, so one can access the functionality separately. The state transformers made into active object by putting them behind a channel in a separate thread and one can invoke actions by writing to the channel. The common functionality provides the connections between the active objects. In this way I would like to create some sort of 'agent' structure, that receive message and process them in their own thread. So far this works quite neat. Wonder if this is they way to go though... Only update (see code below) is a bit ugly (I have no idea why I need fixCastUpdate) and Node itself is probably not necessary, so one level of indirection could be removed. Rest is quite straight forward. Thanks again. Maarten ... (imports) data Node = forall cust. (ICustom cust) = Node cust deriving (Typeable) instance Show Node where-- just for debugging show (Node a) = Node ( ++ show a ++ ) class (Show a, Typeable a) = ICustom a where getVal :: forall b cust. (Typeable b, ICustom cust) = a - (cust - b) - Maybe b getVal a f = case cast a of Nothing - Nothing Just cust - Just (f cust) --update :: oif - (forall a. (ObjectIFace a) = a - a) - IO oif update :: a - (forall b. (ICustom b) = b - b) - a update a f = f a instance ICustom Node where getVal (Node n) f = getVal n f update (Node n) f = Node (update n f) type NodeState a = StateT Node (StateT Common IO) a type Connection = Chan (NodeState ()) type Connections = [Connection] instance Show Connection where show o = Chan (StateT Node (StateT Common IO) ()) -- common part data Common = Common { uid::Integer, connections::Connections } deriving (Show,Typeable) -- custom data data Custom = Custom { val::Integer } deriving (Show,Typeable) instance ICustom Custom where data Custom2 = Custom2 { val2::Integer } deriving (Show,Typeable) instance ICustom Custom2 where -- some function to use common functionality uidM :: NodeState Integer uidM = lift $ gets uid addNodeM :: Connection - NodeState () addNodeM n = lift $ modify (\s - addNode s n) where addNode (Common i ns) nn = (Common i (nn:ns)) getNodeM :: Integer - NodeState Connection getNodeM i = do s - lift $ get return (getNode s i) where getNode (Common _ ns) i = (ns!!(fromInteger i)) getValM f = do s - get return (getVal s f) updateM :: forall a b. (ICustom a, ICustom b) = (a - b) - NodeState () updateM f = do s - get let s' = update s (fixCastUpdate f) put s' fixCastUpdate f st = case (cast st) of Nothing - st Just es - case cast (f es) of Nothing - st Just g - g getStateM = get -- function to create active node functionality action [] = return () action (e:es) = do e s - get-- just for debugging lift $ lift $ putStrLn $ show s action es newBaseState = do uid - newUnique return (Common ((toInteger .hashUnique) uid) []) initAction list state = do bs - newBaseState execStateT (execStateT (action list) state) bs return () send chan action = writeChan chan action sync chan f = do mv - newEmptyMVar send chan (f' mv) a - takeMVar mv return a where f' mv = do a - f lift $ lift $ putMVar mv a newActiveObject action state = do chan - newChan cs - getChanContents chan forkIO (action cs state) return chan -- example main = do let n1 = Node (Custom 5) let n2 = Node (Custom2 6) let n3 = Node (Custom2 7) chan - newActiveObject initAction n1 chan2 - newActiveObject initAction n3 let l = [chan, chan2] mapM_ (\ch - send ch (addNodeM chan)) l mapM_ (\ch - send ch (addNodeM chan2)) l r - mapM (\ch - sync ch (getNodeM 0)) l putStrLn $ r: ++ show r r2 - mapM (\ch - sync ch (uidM)) l putStrLn $ r2: ++ show r2 r3 - mapM (\ch - sync ch (getValM val)) l putStrLn $ r3: ++ show r3 mapM_ (\ch - send ch (updateM (\s - s { val2 = 100 }))) l r5 - mapM (\ch - sync ch (getStateM)) l putStrLn $ r5: ++ show r5 getChar return () ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: ambiguous partially defined type problem
Maarten wrote: Only update (see code below) is a bit ugly (I have no idea why I need fixCastUpdate) class (Show a, Typeable a) = ICustom a where [snip] update :: a - (forall b. (ICustom b) = b - b) - a update a f = f a instance ICustom Node where getVal (Node n) f = getVal n f update (Node n) f = Node (update n f) updateM :: forall a b. (ICustom a, ICustom b) = (a - b) - NodeState () updateM f = do s - get let s' = update s (fixCastUpdate f) put s' Hi Maarten - Looking at this again, I wonder if the following changes would work: -- this change is not strictly necessary update :: a - (a - a) - a updateM :: (forall a. ICustom a = a - a) - NodeState () updateM f = do s - get let s' = update s f put s' I think the reason why fixCastUpdate was needed in your original definition of updateM is because the type of f seems to be too general (a-b) compared to the type of f in the update method of ICustom (b-b) Regards, Brian. -- Logic empowers us and Love gives us purpose. Yet still phantoms restless for eras long past, congealed in the present in unthought forms, strive mightily unseen to destroy us. http://www.metamilk.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: ambiguous partially defined type problem
Brian Hulley wrote: -- this change is not strictly necessary update :: a - (a - a) - a Sorry - I just looked again at the instance decl for Node, so the above change should not be made. Apologies for the multiple posts, I must try to think more before clicking send ;-) Regards, Brian. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ambiguous partially defined type problem
Dear all, For a project involving I use some partially defined node (in this case a simple record, in my project state transformers) in which the defined part is common to all nodes, and the custom part is different for each node. They have to become anonymous so I can put them in a list of connections from each node to another. For some reason GHC complains of 'ambigous type variable' in the code below. The thing is, part of the code may be undefined, but since I'm (explicitly) not using that part, why would GHC care? Are there other solutions to this problem? Any pointers or comments appreciated. Thanks. Maarten (This code is just some dummy code that contains the essence of the problem. I posted the complete code with piggy bagged state transformers in active objects on haskell@haskell.org, but that is rather long and this seems to be the correct mailing list). -- data structure with custom and common part data Node cust = Node cust Common deriving (Show,Typeable) -- anonymous data structure to put use in list data AN = forall ar. (Show ar, Typeable ar) = AN ar instance Show AN where show (AN an) = AN ( ++ show an ++ ) -- common part data Common = Common Integer deriving (Show,Typeable) data Custom = Custom Integer deriving (Show,Typeable) data Custom2 = Custom2 Integer deriving (Show,Typeable) -- extract common part, ignoring type of custom part getCommon :: forall gc. (Node gc) - Common getCommon (Node cust com) = com main = do let a = AN (Node (Custom 5) (Common 10)) let b = case a of (AN a') - getCommon (case (cast a') of Just a'' - a'') putStrLn $ ok: ++ show b ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ambiguous partially defined type problem
Maarten wrote: For a project involving I use some partially defined node (in this case a simple record, in my project state transformers) in which the defined part is common to all nodes, and the custom part is different for each node. They have to become anonymous so I can put them in a list of connections from each node to another. For some reason GHC complains of 'ambigous type variable' in the code below. The thing is, part of the code may be undefined, but since I'm (explicitly) not using that part, why would GHC care? Are there other solutions to this problem? Any pointers or comments appreciated. -- data structure with custom and common part data Node cust = Node cust Common deriving (Show,Typeable) -- anonymous data structure to put use in list data AN = forall ar. (Show ar, Typeable ar) = AN ar instance Show AN where show (AN an) = AN ( ++ show an ++ ) -- common part data Common = Common Integer deriving (Show,Typeable) data Custom = Custom Integer deriving (Show,Typeable) data Custom2 = Custom2 Integer deriving (Show,Typeable) -- extract common part, ignoring type of custom part getCommon :: forall gc. (Node gc) - Common getCommon (Node cust com) = com main = do let a = AN (Node (Custom 5) (Common 10)) let b = case a of (AN a') - getCommon (case (cast a') of Just a'' - a'') putStrLn $ ok: ++ show b Hi Maarten - The problem is that AN is far too general. The compiler can't tell that you've wrapped a Node, so the call to getCommon will fail to typecheck. Even if the compiler did know, by some other means, that a Node had been wrapped, Haskell doesn't support true existentials, so the type signature for getCommon doesn't do what I think you mean ie: getCommon :: forall gc. (Node gc) - Common is the same as writing: getCommon :: Node gc - Common whereas you'd really need an existential: getCommon :: (forall gc. Node gc) - Common The fact that gc is not used in the definition of getCommon doesn't matter, since the type system has to just use the same rules for type inference regardless of the content of the function. In other words, without true existentials, or some other extension to the type system, there is no way to propagate the fact that the actual binding for a type variable is never required. Also, AFAIK there is no guarantee that Node Int Common and Node String Common would always be laid out in memory in the same way - the compiler is allowed to use special optimized layouts for particular instantiations of cust (even though it probably won't be clever enough to do this at the moment in Haskell implementations). I suggest you wrap the custom part separately instead of wrapping the whole Node eg: data Custom = forall cust. ICusom cust = Custom cust data Node = Node Custom Common where the ICustom class is whatever class you need to be able to do anything useful with cust. Alternatively, you could wrap the custom part within the node as in: data Node = forall cust. ICustom cust = Node cust Custom getCommon :: Node - Common getCommon (Node cust com) = com Regards, Brian. -- Logic empowers us and Love gives us purpose. Yet still phantoms restless for eras long past, congealed in the present in unthought forms, strive mightily unseen to destroy us. http://www.metamilk.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] ambiguous partially defined type problem
Hello Brian, Thursday, September 14, 2006, 7:43:55 PM, you wrote: Even if the compiler did know, by some other means, that a Node had been wrapped, Haskell doesn't support true existentials whereas you'd really need an existential: getCommon :: (forall gc. Node gc) - Common they are supported in ghc 6.6 with name of impredicative polymorphism, section 7.4.9 or 7.4.10 of new user manual -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell] Type problem
Hello all, Could I please get some guidance with this? I'm working on implementing a simple relational language in Haskell. I'm trying to construct a data type that can represent values and patterns for a small set of supported types. See code below. HasX is a class of types that have an unconstrained value (xVal). Number is a typical member of that class. Val is my value/pattern data type. P represents a primitive value and T2 is used to make structure. X represents the unconstrained value or a wildcard pattern. It can only be used for types in HasX. The problem is the commented line in the value function. I want to use the xVal method to get the value for X. This is only allowed if I add the constraint (HasX a = ). But I don't want value to have that constraint, since then I cannot run it on pairs. Furthermore, it should be safe without the constraint. ex2 shows that we cannot use X to construct values that are not in HasX. Is this just a limitation of the current GATDs, or is it unreasonable of me to expect this to work? Is there any workaround, such as coercing the type of the value function? -- / Emil {-# OPTIONS -fglasgow-exts #-} class HasX a where xVal :: a data Number = XN -- Unconstrained | N Int -- Constrained instance HasX Number where xVal = XN data Val a where P :: a - Val a -- Primitive T2 :: (Val a1, Val a2) - Val (a1,a2) X :: HasX a = Val a -- Unconstrained value :: Val a - a -- value X= xVal value (P a)= a value (T2 (a1,a2)) = (value a1, value a2) ex1 :: Val (Number,(Number,Number)) ex1 = T2 (P (N 3), T2 (X, P (N 5))) -- ex2 :: Val (Number,Number) -- ex2 = X ___ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
Re: [Haskell] Type problem
I found an acceptable, but not too nice workaround: * Add another class without methods: class HasX a = HasX' a * Make all types that may be unconstrained an instance of this class: instance HasX' Number * Make pairs an instance of HasX (this feels wrong): instance HasX (a1,a2) where xVal = undefined * Add appropriate constraints to the GADT types (X has constraint HasX'): data Val a where P :: a - Val a-- Primitive T2 :: (HasX a1, HasX a2) = (Val a1, Val a2) - Val (a1,a2) X :: HasX' a = Val a -- Unconstrained * Add (HasX a = ) to the value type. At least this is safe. The undefined xVal will never be run. I still wonder if the original idea couldn't work somehow... Thank you, / Emil Emil Axelsson skrev: Hello all, Could I please get some guidance with this? I'm working on implementing a simple relational language in Haskell. I'm trying to construct a data type that can represent values and patterns for a small set of supported types. See code below. HasX is a class of types that have an unconstrained value (xVal). Number is a typical member of that class. Val is my value/pattern data type. P represents a primitive value and T2 is used to make structure. X represents the unconstrained value or a wildcard pattern. It can only be used for types in HasX. The problem is the commented line in the value function. I want to use the xVal method to get the value for X. This is only allowed if I add the constraint (HasX a = ). But I don't want value to have that constraint, since then I cannot run it on pairs. Furthermore, it should be safe without the constraint. ex2 shows that we cannot use X to construct values that are not in HasX. Is this just a limitation of the current GATDs, or is it unreasonable of me to expect this to work? Is there any workaround, such as coercing the type of the value function? ___ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
Re: [Haskell] Type problem
On Tue, Dec 13, 2005 at 09:46:31AM +0100, Emil Axelsson wrote: Is this just a limitation of the current GATDs, or is it unreasonable of me to expect this to work? AFAIK it is a current limitation of GADTs, which will be removed in GHC 6.6. Is there any workaround, such as coercing the type of the value function? I've had the same problem myself. The workaround is to replace some of type-class constraints with witness GADTs. The code I attached shows how you can do it. I chose to make HasX a GADT, and introduce the HasX' type-class, but the latter is only for convenience. Note the subtle change in Val's definition: data Val a where ... X :: HasX a - Val a -- Unconstrained ^^ Best regards Tomasz -- I am searching for a programmer who is good at least in some of [Haskell, ML, C++, Linux, FreeBSD, math] for work in Warsaw, Poland {-# OPTIONS -fglasgow-exts #-} data Number = XN -- Unconstrained | N Int -- Constrained data HasX a where HasX_Number :: HasX Number xVal :: HasX a - a xVal HasX_Number = XN class HasX' a where hasX :: HasX a instance HasX' Number where hasX = HasX_Number x :: HasX' a = Val a x = X hasX data Val a where P :: a - Val a -- Primitive T2 :: (Val a1, Val a2) - Val (a1,a2) X :: HasX a - Val a -- Unconstrained value :: Val a - a value (X hx) = xVal hx value (P a)= a value (T2 (a1,a2)) = (value a1, value a2) ex1 :: Val (Number,(Number,Number)) ex1 = T2 (P (N 3), T2 (x, P (N 5))) -- ex2 :: Val (Number,Number) -- ex2 = X ___ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
Re: [Haskell] Type problem
On Tue, Dec 13, 2005 at 10:42:15AM +0100, Tomasz Zielonka wrote: On Tue, Dec 13, 2005 at 09:46:31AM +0100, Emil Axelsson wrote: Is this just a limitation of the current GATDs, or is it unreasonable of me to expect this to work? AFAIK it is a current limitation of GADTs, which will be removed in GHC 6.6. Of course it is the limitation that will be removed, not GADTs ;-) Best regards Tomasz -- I am searching for a programmer who is good at least in some of [Haskell, ML, C++, Linux, FreeBSD, math] for work in Warsaw, Poland ___ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
Re: [Haskell] Type problem
That's good enough until GHC 6.6. Thank you very much! / Emil Tomasz Zielonka skrev: On Tue, Dec 13, 2005 at 09:46:31AM +0100, Emil Axelsson wrote: Is this just a limitation of the current GATDs, or is it unreasonable of me to expect this to work? AFAIK it is a current limitation of GADTs, which will be removed in GHC 6.6. Is there any workaround, such as coercing the type of the value function? I've had the same problem myself. The workaround is to replace some of type-class constraints with witness GADTs. The code I attached shows how you can do it. I chose to make HasX a GADT, and introduce the HasX' type-class, but the latter is only for convenience. Note the subtle change in Val's definition: data Val a where ... X :: HasX a - Val a -- Unconstrained ^^ Best regards Tomasz {-# OPTIONS -fglasgow-exts #-} data Number = XN -- Unconstrained | N Int -- Constrained data HasX a where HasX_Number :: HasX Number xVal :: HasX a - a xVal HasX_Number = XN class HasX' a where hasX :: HasX a instance HasX' Number where hasX = HasX_Number x :: HasX' a = Val a x = X hasX data Val a where P :: a - Val a -- Primitive T2 :: (Val a1, Val a2) - Val (a1,a2) X :: HasX a - Val a -- Unconstrained value :: Val a - a value (X hx) = xVal hx value (P a)= a value (T2 (a1,a2)) = (value a1, value a2) ex1 :: Val (Number,(Number,Number)) ex1 = T2 (P (N 3), T2 (x, P (N 5))) -- ex2 :: Val (Number,Number) -- ex2 = X ___ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
Re: [Haskell-cafe] existential type problem
data Bar a m = forall t. (MonadTrans t, Monad (t m)) = Bar (t m a - m a) (t m Int) data Foo = Foo (forall a m. Monad m = Bar a m) Is it true that I cannot have a function foo run op = Foo (Bar run op) I guess the answer is yes and no. Let's consider the type of 'op': exists t. forall m. (MonadTrans t, Monad m, Monad (t m)) = t m Int obviously, we can't write such a type expression in Haskell. There are two work-arounds however. First, we can perform existential instantiation: that is, replace t with some specific type (type constructor, that is). We should also make sure that MonadTrans t and Monad (t m) constraints are satisfied after such a replacement (the typechecker will complain otherwise). So, we come to one known solution: myFoo :: Int - Foo myFoo i = Foo (Bar run op) where run :: Monad m = StateT Int m a - m a run prog = do (a, s) - runStateT prog i return a op :: Monad m = StateT Int m Int op= get Here, we replaced t with the specific type constructor StateT. Another way of handling the above type for 't' -- another way of getting rid of the existential quantification -- is to negate the type expression. In other words, make that 'op' an argument of a function, and be sure that 't' doesn't show up in the result. But that's what our 'Bar' already does: *P :t Bar Bar :: forall m a t. (Monad (t m), MonadTrans t) = (t m a - m a) - t m Int - Bar a m We note that t is not a function of m, so the order of quantification will indeed be exists t. forall m. That's how we recover the two-step solution, with Foo and Bar. ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] existential type problem
On Sat, Oct 16, 2004 at 05:54:46AM +, [EMAIL PROTECTED] wrote: data Bar a m = forall t. (MonadTrans t, Monad (t m)) = Bar (t m a - m a) (t m Int) data Foo = Foo (forall a m. Monad m = Bar a m) Is it true that I cannot have a function foo run op = Foo (Bar run op) because it does not have an expressible type? Or is there some way to make ghc accept this? Obviously, this expression can be used in the context of a larger expression. myFoo :: Int - Foo myFoo i = Foo (Bar run op) where run :: Monad m = StateT Int m a - m a run prog = do (a, s) - runStateT prog i return a op :: Monad m = StateT Int m Int op= get Andrew ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] existential type problem
On Fri, Oct 15, 2004 at 07:54:46PM -0700, [EMAIL PROTECTED] wrote: Andrew Pimlott wrote: I want values in my existential type to denote, for some monad, a monadic operation and a way to run the monad. Except, I want it mix the operation with operations in another monad, so it use a monad transformer. I'm afraid, that phrase was a little misleading. It seems that you meant: - encapsulate one _specific_ monad transformer - to be able to apply it to _any_ (not some!) monad Yes. I wrote that quickly (grammar mistakes too) and thought the code would make it clear. But it would have been better to make the words precise. data Bar a m = forall t. (MonadTrans t, Monad (t m)) = Bar (t m a - m a) (t m Int) data Foo = Foo (forall a m. Monad m = Bar a m) Wow, very nice. Just do it in two steps! Thank you for this enlightening solution. Andrew ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] existential type problem
I'm having trouble using an existential type, becasue of what seem to be limitations in how I can express the type. I want values in my existential type to denote, for some monad, a monadic operation and a way to run the monad. Except, I want it mix the operation with operations in another monad, so it use a monad transformer. Specifically: data Foo = forall t. (MonadTrans t) = Foo ((Monad m, Monad (t m)) = t m a - m a)-- run ((Monad m, Monad (t m)) = t m Int) -- op prog :: Foo - IO Int prog (Foo run op) = run $ do lift $ putStrLn Running prog op ghci gives the error Could not deduce (Monad (t IO)) from the context (MonadTrans t) arising from use of `op' at try.hs:22 Hmm I see that my constraints did not mean what I expected. As the Probable fix suggests, I can add Monad (t IO) to the existential context to make this code type check, but I want it to work for all monads, not just IO. Something like data Foo = forall t. (MonadTrans t, (forall m. Monad m = Monad (t m))) = Foo ... But I haven't found anything like that. I would also welcome other approaches to this problem. Andrew ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] existential type problem
On Fri, 15 Oct 2004 19:55:02 -0400 Andrew Pimlott [EMAIL PROTECTED] wrote: data Foo = forall t. (MonadTrans t) = Foo ((Monad m, Monad (t m)) = t m a - m a)-- run ((Monad m, Monad (t m)) = t m Int) -- op prog :: Foo - IO Int prog (Foo run op) = run $ do lift $ putStrLn Running prog op ghci gives the error Could not deduce (Monad (t IO)) from the context (MonadTrans t) arising from use of `op' at try.hs:22 Your prog leaks m (= IO) out of Foo. I guess you mean: data Foo m = forall t. (MonadTrans t, Monad (t m)) = Foo (forall a. t m a - m a) (t m Int) prog :: Foo IO - IO Int prog (Foo run op) = run $ do lift $ putStrLn Running prog op test = prog (Foo (flip evalStateT 0) get) -- Koji Nakahara ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] existential type problem
On Sat, Oct 16, 2004 at 10:19:14AM +0900, Koji Nakahara wrote: On Fri, 15 Oct 2004 19:55:02 -0400 Andrew Pimlott [EMAIL PROTECTED] wrote: data Foo = forall t. (MonadTrans t) = Foo ((Monad m, Monad (t m)) = t m a - m a)-- run ((Monad m, Monad (t m)) = t m Int) -- op prog :: Foo - IO Int prog (Foo run op) = run $ do lift $ putStrLn Running prog op ghci gives the error Could not deduce (Monad (t IO)) from the context (MonadTrans t) arising from use of `op' at try.hs:22 Your prog leaks m (= IO) out of Foo. I guess you mean: data Foo m = forall t. (MonadTrans t, Monad (t m)) = Foo (forall a. t m a - m a) (t m Int) prog :: Foo IO - IO Int prog (Foo run op) = run $ do lift $ putStrLn Running prog op test = prog (Foo (flip evalStateT 0) get) But my implementation may look like myFoo :: Int - Foo myFoo i = Foo run op where run :: Monad m = StateT Int m a - m a run prog = do (a, s) - runStateT prog i return a op :: Monad m = StateT Int m Int op= get which works for all monads, not just IO (that is the idea of using a tranformer). So I really don't want to encode that type in Foo. Andrew ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] existential type problem
Andrew Pimlott wrote: I want values in my existential type to denote, for some monad, a monadic operation and a way to run the monad. Except, I want it mix the operation with operations in another monad, so it use a monad transformer. I'm afraid, that phrase was a little misleading. It seems that you meant: - encapsulate one _specific_ monad transformer - to be able to apply it to _any_ (not some!) monad That is, the transformer must be existentially quantified, and the monad must be universally quantified. Once that is clear, the solution is straightforward. {-# OPTIONS -fglasgow-exts #-} module P where import Control.Monad.Trans import Control.Monad.State data Bar a m = forall t. (MonadTrans t, Monad (t m)) = Bar (t m a - m a) (t m Int) data Foo = Foo (forall a m. Monad m = Bar a m) prog :: Foo - IO Int prog (Foo x) = case x of Bar run op - run $ do lift $ putStrLn Running prog op test:: IO Int test = prog (Foo x) where -- to be used in a higher-ranked type: signature required x:: Monad m = Bar a m x = Bar (flip evalStateT 0) get myFoo :: Int - Foo myFoo i = Foo (Bar run op) where run :: Monad m = StateT Int m a - m a run prog = do (a, s) - runStateT prog i return a op :: Monad m = StateT Int m Int op= get test1 = prog (myFoo 10) ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Existential type... problem...
Hello all, Just got an interesting error, which I can't really understand (but that DOES happen a lot...). Trying to work with existention types, record types, and wrapping the whole thing up in a nice IORef for my uses: data ETable = forall a. EditableTable a = ETable a data GuiRecord = GuiRecord {gtable :: ETable, moz :: MozEmbed, pos :: Position, ent :: Entry} type GuiState = IORef (GuiRecord) Generates the following error: Couldn't match `* - Type bx' against `*' In the type synonym declaration for `GuiState' Anyone have any ideas?? Thanks in advance! Regards, Scott ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Existential type... problem...
On Tue, Jul 27, 2004 at 07:48:01PM -0400, Scott West wrote: Hello all, Just got an interesting error, which I can't really understand (but that DOES happen a lot...). Trying to work with existention types, record types, and wrapping the whole thing up in a nice IORef for my uses: data ETable = forall a. EditableTable a = ETable a data GuiRecord = GuiRecord {gtable :: ETable, moz :: MozEmbed, pos :: Position, ent :: Entry} type GuiState = IORef (GuiRecord) Generates the following error: Couldn't match `* - Type bx' against `*' In the type synonym declaration for `GuiState' Anyone have any ideas?? Thanks in advance! I wried the following, and didn't get an error: data ETable = forall a. Eq a = ETable a data GuiRecord = GuiRecord {gtable :: ETable, moz ::(), pos :: (), ent :: ()} type GuiState = IORef (GuiRecord) are you sure EditableTable, MozEmbed, Position, and Entry don't take type arguments? because that would explain the error message (but it is odd that it is being reported at the type declaration) John -- John Meacham - repetae.netjohn ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
type problem
Is there any way to insist that two types are different? For example f :: NotSame a b = a - b Regards, Keean Schupke. ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Type Problem
Hi, I am wondering how can I pass an overloaded function as a parameter to another function. Consider the following example. I want to tell the compiler that the argument `fun' in `trickyFun' definition is always either ord' or chr', and hence it can find the correct overloaded version in both the cases (1) (2). Thanks, Saswat class X a where ord' :: a - Int chr' :: a - Char instance X Int where ord' = id chr' = chr instance X Char where ord' = ord chr' = id trickyFun fun = let x = fun (2::Int) ---(1) y = fun 'c'---(2) in tricky ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
Re: Type Problem
Sun, 16 Sep 2001 16:28:01 +0800 (GMT-8), Saswat Anand [EMAIL PROTECTED] pisze: trickyFun fun = let x = fun (2::Int) ---(1) y = fun 'c'---(2) in tricky It can't be done this way in standard Haskell. In GHC and Hugs you can use local universal quantifaction by writing explicit type signature: trickyFun :: (forall a. X a = a - b) - String GHC needs to be run with -fglasgow-exts, Hugs needs -98. GHC user's guide describes some limitations, e.g. trickyFun must always be directly applied to an argument. -- __( Marcin Kowalczyk * [EMAIL PROTECTED] http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZASTÊPCZA QRCZAK ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
Re: Type problem with ST monad
Sigbjorn Finne wrote: forwarding to the mailing list is restricted to off-hours only at the moment, but thought I'd suggest a solution to you before then - use a (universally quantified) pattern matching function rather than a pattern binding, i.e., deTIM :: TIM s a - ST s a deTIM (TIM m) = m runTIM :: (forall s. TIM s a) - Maybe a runTIM m = runST (deTIM m) Thank you very much. I thought I had tried this, but now I note that when I used the projection I forgot to give the type signature for runTIM... Maybe you could mention this problem its solution in the ghc manual section about second order types. -- OLAF CHITIL, Lehrstuhl fuer Informatik II, RWTH Aachen, 52056 Aachen, Germany Tel: (+49/0)241/80-21212; Fax: (+49/0)241/-217 URL: http://www-i2.informatik.rwth-aachen.de/~chitil/