Re: [Haskell-cafe] Store type-class polymorphic values generically

2013-10-11 Thread Christopher Done
In other words, the API is only changed in that an additional binding has been exported for each top-level definition to which you can write (only of the correct type) a new definition. This is something that you could do manually, write it by hand, but I want it automatic for any module I load into GHCi

[Haskell-cafe] Converting MPTC+fundeps to type family / problem with polymorphic constant. Roles?

2013-10-06 Thread Ryan Newton
The abstract-par class has used multi-parameter type classes with fundeps: http://hackage.haskell.org/package/abstract-par-0.3.1/docs/Control-Monad-Par-Class.html#g:1 And I'm trying to port it to use type families. But the following combination seems to be completely unusable for me right now

Re: [Haskell-cafe] Converting MPTC+fundeps to type family / problem with polymorphic constant. Roles?

2013-10-06 Thread Ryan Newton
Oops, right after I sent I realized the answer ;-). I needed to delete one character to uncurry the type function. That is: type Future m instead of type Future m a The fixed version is here: https://github.com/iu-parfunc/lvars/blob/2b733d3044fde861e9c9b181258e7f9865afa204/haskell/par

Re: [Haskell-cafe] Store type-class polymorphic values generically

2013-10-04 Thread Heinrich Apfelmus
Christopher Done wrote: It's very easy to state this problem without enough details and mislead people into providing a solution for a different problem, so I'll try to include all the information and use-case. I need a function that can store a value in a concrete opaque type. I know the type

Re: [Haskell-cafe] Store type-class polymorphic values generically

2013-10-04 Thread Christopher Done
On 4 October 2013 10:56, Heinrich Apfelmus apfel...@quantentunnel.de wrote: In particular, the Locker stores arbitrary values like Dynamic , except that values are extracted and removed with the help of a Key . This gets rid of the Typeable constraint. lock :: Key a - a - Locker I can't

Re: [Haskell-cafe] Store type-class polymorphic values generically

2013-10-04 Thread Heinrich Apfelmus
:: Key a - a - Locker I can't pass anything with class constraints to that. I don't know what something with a class constraint means. But I guess you want to pass a value with a *polymorphic* type? This is no problem, but requires impredicative polymorphism: a = (forall b. Show b = b - IO

Re: [Haskell-cafe] Store type-class polymorphic values generically

2013-10-04 Thread Simon Peyton-Jones
| However, I want to write this as a core-to-core | translation as a ghc-plugin. I want the definition go = putStrLn Hello | World! to be translated to what I wrote above. Core cannot generate new | names to be exported from a module, so go_ is now gone. Wait... what do you mean Core cannot

Re: [Haskell-cafe] Store type-class polymorphic values generically

2013-10-04 Thread Alp Mestanogullari
Hi Chris, Maybe this package (from Edward Kmett, surprisingly) could help: http://hackage.haskell.org/package/constraints-0.3.3/docs/Data-Constraint.html? Considering it kind of reifies the type class constraints, I'm wondering whether you could use this to carry the constraints along the value

[Haskell-cafe] Store type-class polymorphic values generically

2013-10-03 Thread Christopher Done
It's very easy to state this problem without enough details and mislead people into providing a solution for a different problem, so I'll try to include all the information and use-case. I need a function that can store a value in a concrete opaque type. I know the type of the value when I store

Re: [Haskell-cafe] type-level integers, type-level operators, and most specific overlapping instance

2013-09-22 Thread TP
TP wrote: But I have still a question: is the behavior of GHC correct in the example of my initial post? See here: http://www.haskell.org/ghc/docs/7.6.3/html/users_guide/type-class-extensions.html#instance-overlap When matching, GHC takes no account of the context of the instance

Re: [Haskell-cafe] type-level integers, type-level operators, and most specific overlapping instance

2013-09-22 Thread adam vogt
On Sun, Sep 22, 2013 at 11:07 AM, TP paratribulati...@free.fr wrote: My misunderstanding came from a confusion between a context and a constraint. The context is what is before the =, and the constraint is what is after, i.e. the main part of the instance declaration. Hi TP, I think context

Re: [Haskell-cafe] type-level integers, type-level operators, and most specific overlapping instance

2013-09-22 Thread TP
Constraint. In other words: instance Context = InstanceHead instance (Constraint, Constraint2) = InstanceHead This is indeed more in accordance with what I believe to be a context or a constraint. But, it seems that in this page http://www.haskell.org/ghc/docs/7.6.3/html/users_guide/type

[Haskell-cafe] type-level integers, type-level operators, and most specific overlapping instance

2013-09-21 Thread TP
. file:///usr/share/doc/ghc-doc/html/users_guide/type-class- extensions.html#instance-overlap How to make GHC realize that in the second instance below, the instance context is not satisfied, such that the first instance has to be used? (Indeed, a Scalar is a `Tensor 'Zero`, so the strict

Re: [Haskell-cafe] type-level integers, type-level operators, and most specific overlapping instance

2013-09-21 Thread adam vogt
-doc/html/users_guide/type-class- extensions.html#instance-overlap How to make GHC realize that in the second instance below, the instance context is not satisfied, such that the first instance has to be used? (Indeed, a Scalar is a `Tensor 'Zero`, so the strict inequality `'Zero : n

Re: [Haskell-cafe] type-level integers, type-level operators, and most specific overlapping instance

2013-09-21 Thread TP
FlexibleInstances #-} {-# LANGUAGE OverlappingInstances #-} import Prelude hiding ((*)) data Nat = Zero | Succ Nat deriving ( Show, Eq, Ord ) data Tensor :: Nat - * where Tensor :: Tensor order Mult :: Scalar - Tensor order - Tensor order deriving instance Show (Tensor order) type

[Haskell-cafe] Transforming AST parametrized with type

2013-09-10 Thread Sergey Mironov
a) } data Id a = Id { name :: a } from Expr String to, say, Expr Int where Int names may represent some keys in the hash map? Regards, Sergey [1] - http://stackoverflow.com/questions/5434889/is-it-possible-to-use-syb-to-transform-the-type PS sclv suggested to use synthesize from SYB to solve

Re: [Haskell-cafe] type constructor section for (- Bool), _not_ ((-) Bool)

2013-09-04 Thread AntC
Brent Yorgey byorgey at seas.upenn.edu writes: On Tue, Sep 03, 2013 at 11:33:46AM +, AntC wrote: I want an instance and type improvement constraint of the form instance (f ~ (- Bool)) = C Foo (f b) where ... There is no operator section syntax for types. Moreover

[Haskell-cafe] type constructor section for (- Bool), _not_ ((-) Bool)

2013-09-03 Thread AntC
I'm probably being dumb, but Hoogle nor the wiki are helping me. I want an instance and type improvement constraint of the form instance (f ~ (- Bool)) = C Foo (f b) where ... The first arg to C is driving type improvement, for example: instance (f ~ []) = C Bar (f b) where

Re: [Haskell-cafe] type constructor section for (- Bool), _not_ ((-) Bool)

2013-09-03 Thread Brent Yorgey
On Tue, Sep 03, 2013 at 11:33:46AM +, AntC wrote: I'm probably being dumb, but Hoogle nor the wiki are helping me. I want an instance and type improvement constraint of the form instance (f ~ (- Bool)) = C Foo (f b) where ... The first arg to C is driving type improvement

Re: [Haskell-cafe] Extending Type Classes

2013-08-27 Thread Simon Peyton-Jones
] Extending Type Classes | | | The problem of refinement of type classes annoys me from time to time | when I work on the NumericPrelude. It is an experimental type class | hierarchy for mathematical types. Sometimes a new data type T shall be | implemented and it turns out that you can implement

Re: [Haskell-cafe] Extending Type Classes

2013-08-26 Thread Henning Thielemann
The problem of refinement of type classes annoys me from time to time when I work on the NumericPrelude. It is an experimental type class hierarchy for mathematical types. Sometimes a new data type T shall be implemented and it turns out that you can implement only a part of all methods

Re: [Haskell-cafe] What am I missing? Cycle in type synonym declarations

2013-08-21 Thread Simon Peyton-Jones
GHC tries to typecheck quotations. In this case it's trying to typecheck the declaration type Bar = FooT $t Part of type checking is rejecting recursive type synonyms. Here GHC is rejecting it because it *might* be recursive, depending on how $t is filled in. The trouble is that we

[Haskell-cafe] What am I missing? Cycle in type synonym declarations

2013-08-20 Thread David Fox
This file gives me the error Cycle in type synonym declarations Can anyone tell me why? I'm just trying to write a function to create a type that is a FooT with the type parameter fixed. {-# LANGUAGE TemplateHaskell #-} import Language.Haskell.TH (Q, Dec, TypeQ) data FooT a = FooT a foo

Re: [Haskell-cafe] What am I missing? Cycle in type synonym declarations

2013-08-20 Thread jabolopes
Hi, In this case, you have two 'FooT' names: one is the Type and the other is the Constructor. Perhaps Template Haskell is capturing the wrong one inside the quote (probably the constructor). When you have name shadowing, you should always use a lookup function. You can find these lookup

Re: [Haskell-cafe] What am I missing? Cycle in type synonym declarations

2013-08-20 Thread adam vogt
On Tue, Aug 20, 2013 at 5:00 PM, David Fox d...@seereason.com wrote: This file gives me the error Cycle in type synonym declarations Can anyone tell me why? I'm just trying to write a function to create a type that is a FooT with the type parameter fixed. {-# LANGUAGE TemplateHaskell

Re: [Haskell-cafe] What am I missing? Cycle in type synonym declarations

2013-08-20 Thread David Fox
On Tue, Aug 20, 2013 at 2:35 PM, adam vogt vogt.a...@gmail.com wrote: On Tue, Aug 20, 2013 at 5:00 PM, David Fox d...@seereason.com wrote: This file gives me the error Cycle in type synonym declarations Can anyone tell me why? I'm just trying to write a function to create a type

Re: [Haskell-cafe] Database.postgreSQL.Simple - ambigious type

2013-08-18 Thread Hartmut Pfarr
:: IO [Int]) or give hello a monomorphic type signature, such as hello :: IO [Int] Tom ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] Database.postgreSQL.Simple - ambigious type

2013-08-18 Thread Tom Ellis
On Sun, Aug 18, 2013 at 10:16:06PM +0200, Hartmut Pfarr wrote: I played a bit with your suggestion, and it is running now :-) But instead of IO [Int] I think we need IO [Only Int] because of the 1-element-tupel problem? Yes you're right. I had forgotten that postgresql-simple dealt with

[Haskell-cafe] Database.postgreSQL.Simple - ambigious type

2013-08-17 Thread Hartmut Pfarr
Hello, I've a problem connecting to my postgresql database. Can You help me fix the ambigious type signature? (The example is identical to the first 5-liner-example in the package documentation) http://hackage.haskell.org/packages/archive/postgresql-simple/0.3.5.0/doc/html/Database

Re: [Haskell-cafe] Database.postgreSQL.Simple - ambigious type

2013-08-17 Thread Brandon Allbery
On Sat, Aug 17, 2013 at 1:35 PM, Hartmut Pfarr hartmut0...@googlemail.comwrote: (The example is identical to the first 5-liner-example in the package documentation) As I read it, the example has a typo: it should be using `query_` instead of `query`. See

Re: [Haskell-cafe] Database.postgreSQL.Simple - ambigious type

2013-08-17 Thread Hartmut Pfarr
Thx, I changed now from query to query_ Now the coding is like that: {-# LANGUAGE OverloadedStrings #-} import Database.PostgreSQL.Simple import Database.PostgreSQL.Simple.FromRow hello :: (FromRow a) = IO [a] hello = do

Re: [Haskell-cafe] Database.postgreSQL.Simple - ambigious type

2013-08-17 Thread Tom Ellis
main = print = (hello :: IO [Int]) or give hello a monomorphic type signature, such as hello :: IO [Int] Tom ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] Database.postgreSQL.Simple - ambigious type

2013-08-17 Thread Brandon Allbery
On Sat, Aug 17, 2013 at 5:59 PM, Hartmut Pfarr hartmut0...@googlemail.comwrote: query_ conn select 2 + 2 I've no errors any more. But: I don't see any result (for sure, it is not coeded yet) Yes, because you're not capturing it; it's the return value from `query_`, which you are throwing

Re: [Haskell-cafe] Database.postgreSQL.Simple - ambigious type

2013-08-17 Thread Hartmut Pfarr
... thx all for helping. Now the coding works: it puts the following out. Kind regards Hartmut *Main main Only {fromOnly = 4} -- Only {fromOnly = 101} Only {fromOnly = 102} Only {fromOnly = 103} -- blub 101 51 blub 102 52 blub 103 53 The

[Haskell-cafe] Are type families really this slow, or is this a GHC bug?

2013-07-26 Thread Mike Izbicki
I'm using the TypeFamilies extension to generate types that are quite large. GHC can handle these large types fine when they are created manually, but when type families get involved, GHC's performance dies. It's doing in quadratic time what looks to me like it should be linear time. I don't

Re: [Haskell-cafe] Are type families really this slow, or is this a GHC bug?

2013-07-26 Thread Jan Stolarek
I don't know much about type families, but I recall this: http://ghc.haskell.org/trac/ghc/ticket/5321 The bug is marked as fixed, but perhaps behaviour you observed shows that there are other cases where constraqint solver is slow. I'd consider reporting this as GHC bug. Janek

Re: [Haskell-cafe] Are type families really this slow, or is this a GHC bug?

2013-07-26 Thread Mike Izbicki
Thanks for pointing to that ticket. At first after reading through it, I thought my mistake was not using tail call recursion. But I updated the type families and they actually ran slower! I've gone ahead and reported a bug: http://ghc.haskell.org/trac/ghc/ticket/8095 On Fri, Jul 26, 2013

Re: [Haskell-cafe] Wrapping all fields of a data type in e.g. Maybe

2013-07-21 Thread Michael Orlitzky
On 07/20/2013 04:49 PM, adam vogt wrote: Hi Michael, It's fairly straightforward to generate the new data with template haskell [1], and on the same page, section 10.7 'generic' zipWith is likely to be similar to your merging code. [1]

Re: [Haskell-cafe] Wrapping all fields of a data type in e.g. Maybe

2013-07-20 Thread adam vogt
On Sat, Jul 20, 2013 at 12:14 AM, Michael Orlitzky mich...@orlitzky.com wrote: For posterity, I report failure =) Hi Michael, It's fairly straightforward to generate the new data with template haskell [1], and on the same page, section 10.7 'generic' zipWith is likely to be similar to your

Re: [Haskell-cafe] Wrapping all fields of a data type in e.g. Maybe

2013-07-19 Thread Michael Orlitzky
On 07/16/2013 04:57 PM, Michael Orlitzky wrote: This all works great, except that when there's 20 or so options, I duplicate a ton of code in the definition of OptionalCfg. Is there some pre-existing solution that will let me take a Cfg and create a new type with Cfg's fields wrapped

[Haskell-cafe] Wrapping all fields of a data type in e.g. Maybe

2013-07-16 Thread Michael Orlitzky
I have a common pattern in my command-line programs; I start out with a configuration data type, which over-simplified looks like: data Cfg = Cfg { verbose :: Bool } Now, there's usually a default configuration, default :: Cfg default = Cfg False The user can override the defaults one

Re: [Haskell-cafe] Wrapping all fields of a data type in e.g. Maybe

2013-07-16 Thread Tom Ellis
On Tue, Jul 16, 2013 at 04:57:59PM -0400, Michael Orlitzky wrote: This all works great, except that when there's 20 or so options, I duplicate a ton of code in the definition of OptionalCfg. Is there some pre-existing solution that will let me take a Cfg and create a new type with Cfg's fields

Re: [Haskell-cafe] Wrapping all fields of a data type in e.g. Maybe

2013-07-16 Thread Oliver Charles
On 07/16/2013 09:57 PM, Michael Orlitzky wrote: I have a common pattern in my command-line programs; I start out with a configuration data type, which over-simplified looks like: data Cfg = Cfg { verbose :: Bool } Now, there's usually a default configuration, default :: Cfg

Re: [Haskell-cafe] Wrapping all fields of a data type in e.g. Maybe

2013-07-16 Thread Michael Orlitzky
a Cfg and create a new type with Cfg's fields wrapped in Maybe? You can always try data Cfg f = Cfg { verbose :: f Bool } and set f to Maybe or Identity depending on what you use it for. It will be slightly notationally cumbersome to extract values from the Identity functor though

Re: [Haskell-cafe] Wrapping all fields of a data type in e.g. Maybe

2013-07-16 Thread John Lato
The suggestion of parameterizing on a functor would be good, however there's another approach I've often seen (although it's not quite what you've asked for). You can leave your config datatype alone, but instead of making it a monoid have your configuration parsers return functions with the type

Re: [Haskell-cafe] Wrapping all fields of a data type in e.g. Maybe

2013-07-16 Thread David Thomas
often seen (although it's not quite what you've asked for). You can leave your config datatype alone, but instead of making it a monoid have your configuration parsers return functions with the type (Cfg - Cfg). You can wrap these functions in Endo to get a monoid, combine them together

Re: [Haskell-cafe] Wrapping all fields of a data type in e.g. Maybe

2013-07-16 Thread Michael Orlitzky
configuration parsers return functions with the type (Cfg - Cfg). You can wrap these functions in Endo to get a monoid, combine them together, and then apply that function to the default configuration. I'm using cmdargs for the command-line parsing, and I think (if I don't want to abandon its magic

[Haskell-cafe] Homotopy Type Theory IRC Channel

2013-07-15 Thread Darin Morrison
Hello, I know there are many haskellers interested in dependent type theory so I wanted to mention that there is now an IRC channel on freenode for discussing Homotopy Type Theory (HoTT), e.g., the recent book, possible implementations, dependent type theory in general, etc. The channel

[Haskell-cafe] Reify type

2013-07-12 Thread Jose A. Lopes
Hello everyone, Is there a way to automatically reify a type ? In other words, to do the following: reifyType (LitT ...) = ConT ''LitT ... I am using Template Haskell and I want the generated code to have access to Type datatypes that were available to the Template Haskell code. Cheers, Jose

Re: [Haskell-cafe] Reify type

2013-07-12 Thread Michael Sloan
Hello! I'm not sure if this is what you're asking for, as it doesn't fit that line of code. 'LitT' is a data constructor not a type constructor. So instead it'd be reifyType (LitT ...) = ConE 'LitT ... If this is what you're looking for, then 'lift' is what you want: http

Re: [Haskell-cafe] Reify type

2013-07-12 Thread Jose A. Lopes
That's exactly what I mean! I'll give it a try. Thanks Michael, Jose ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] Reify type

2013-07-12 Thread Jose A. Lopes
Hello, I am getting the following error message: No instance for (Lift Type) arising from a use of `lift' Possible fix: add an instance declaration for (Lift Type) I have imported Language.Haskell.TH.Instances. Is there anything else I have to do ? Regards, Jose

Re: [Haskell-cafe] Reify type

2013-07-12 Thread Michael Sloan
wrote: Hello, I am getting the following error message: No instance for (Lift Type) arising from a use of `lift' Possible fix: add an instance declaration for (Lift Type) I have imported Language.Haskell.TH.Instances. Is there anything else I have to do ? Regards, Jose

Re: [Haskell-cafe] Is the following implemented by a sparse matrix representation? type Graph n w = Array (n, n) (Maybe w)

2013-07-10 Thread Thomas Horstmeyer
are in the graph. But perhaps I misunderstood your question. Thomas Am 09.07.2013 23:26, schrieb KC: type Graph n w = Array (n,n) (Maybe w) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] Is the following implemented by a sparse matrix representation? type Graph n w = Array (n, n) (Maybe w)

2013-07-10 Thread Twan van Laarhoven
is slightly different, and there will be different trade-offs. Twan On 09/07/13 23:26, KC wrote: Is the following implemented by a sparse matrix representation? type Graph n w = Array (n,n) (Maybe w) -- -- Regards, KC ___ Haskell-Cafe mailing

Re: [Haskell-cafe] Is the following implemented by a sparse matrix representation? type Graph n w = Array (n, n) (Maybe w)

2013-07-10 Thread KC
like IntMap (IntMap w) or Map (n,n) w or Array n (IntMap w). Each of these representations is slightly different, and there will be different trade-offs. Twan On 09/07/13 23:26, KC wrote: Is the following implemented by a sparse matrix representation? type Graph n w = Array (n,n) (Maybe w

[Haskell-cafe] Is the following implemented by a sparse matrix representation? type Graph n w = Array (n, n) (Maybe w)

2013-07-09 Thread KC
type Graph n w = Array (n,n) (Maybe w) -- -- Regards, KC ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] same function's type accepted in top level, but rejected in where clause

2013-07-08 Thread Chaddaï Fouché
On Fri, Jul 5, 2013 at 11:03 PM, Ömer Sinan Ağacan omeraga...@gmail.comwrote: There's an implicit quantifier in type of `f`, like this: `f :: forall a. a - ListF a a`. When I add `ScopedTypeVariables` and `forall a. ...` in top level definition, it's like all `a`s in scope of top level

Re: [Haskell-cafe] same function's type accepted in top level, but rejected in where clause

2013-07-08 Thread Mateusz Kowalczyk
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 08/07/13 19:50, Chaddaï Fouché wrote: On Fri, Jul 5, 2013 at 11:03 PM, Ömer Sinan A?acan omeraga...@gmail.comwrote: There's an implicit quantifier in type of `f`, like this: `f :: forall a. a - ListF a a`. When I add `ScopedTypeVariables

Re: [Haskell-cafe] Casting newtype to base type?

2013-07-06 Thread Ozgur Akgun
Hi Vlatko. On 2 July 2013 16:03, Vlatko Basic vlatko.ba...@gmail.com wrote: Is there a nicer way to extract the 'IO String' from 'IOS', without 'case' or without pattern matching the whole 'P'? You might enjoy the newtype package. http://hackage.haskell.org/package/newtype Hope this helps,

[Haskell-cafe] Extending Type Classes

2013-07-05 Thread Frantisek Farka
Hello all, I was looking for my master thesis topic and my supervisor suggested an idea of extending class system so it enables refactoring Type Class hierarchy without affecting client source code which is using refactored classes. One example is Functor - Applicative - Monad problem

[Haskell-cafe] same function's type accepted in top level, but rejected in where clause

2013-07-05 Thread Ömer Sinan Ağacan
Hi all, I came across an interesting type checker error, a function is accepted in top level, but rejected by type checker when moved to `where ...` clause. I moved required code to a new module for demonstration purposes: module Bug where fix :: (a - a) - a fix f = let x = f x

Re: [Haskell-cafe] same function's type accepted in top level, but rejected in where clause

2013-07-05 Thread David McBride
If you remove the type signature from f in the where clause it will work. The reason is because the type signature listed there, the a is a different a than in the top level signature. If you change it from a to x, it says it should be the a that you can't seem to specify. If you add the pragma

Re: [Haskell-cafe] same function's type accepted in top level, but rejected in where clause

2013-07-05 Thread Ömer Sinan Ağacan
understand, the problem is because in this definition: where f :: a - ListF a a f a = ConsF a (fn a) There's an implicit quantifier in type of `f`, like this: `f :: forall a. a - ListF a a`. When I add `ScopedTypeVariables` and `forall a. ...` in top level definition, it's like all `a`s

Re: [Haskell-cafe] Casting newtype to base type?

2013-07-02 Thread Vlatko Basic
of IOS a - a getC_IO (P _ _ (IOS a)) = a Original Message Subject: Re: [Haskell-cafe] Casting newtype to base type? From: Malcolm Wallace malcolm.wall...@me.com To: vlatko.ba...@gmail.com Cc: Haskell-Cafe haskell-cafe@haskell.org Date: 01.07.2013 17:24 On 1 Jul 2013, at 16:07

Re: [Haskell-cafe] Casting newtype to base type?

2013-07-02 Thread Tom Ellis
On Tue, Jul 02, 2013 at 03:03:08PM +0200, Vlatko Basic wrote: Is there a nicer way to extract the 'IO String' from 'IOS', without 'case' or without pattern matching the whole 'P'? newtype IOS = IOS (IO String) data P = P { getA :: String, getB :: String, getC :: IOS } deriving

Re: [Haskell-cafe] Casting newtype to base type?

2013-07-02 Thread Vlatko Basic
Original Message Subject: Re: [Haskell-cafe] Casting newtype to base type? From: Tom Ellis tom-lists-haskell-cafe-2...@jaguarpaw.co.uk To: haskell-cafe@haskell.org Date: 02.07.2013 15:25 On Tue, Jul 02, 2013 at 03:03:08PM +0200, Vlatko Basic wrote: Is there a nicer way

Re: [Haskell-cafe] Casting newtype to base type?

2013-07-02 Thread David McBride
You could always just put it into your newtype: newtype IOS = IOS { unIOS :: IO String } On Tue, Jul 2, 2013 at 9:31 AM, Vlatko Basic vlatko.ba...@gmail.com wrote: Original Message Subject: Re: [Haskell-cafe] Casting newtype to base type? From: Tom Ellis tom-lists

[Haskell-cafe] Casting newtype to base type?

2013-07-01 Thread Vlatko Basic
I try to set 'c' field in fun :: FilePath - P - IO P fun path p = do b - doesFileExist path ... return $ p {c = readFile path} I get error Couldn't match expected type `IOS' with actual type `IO String' which is correct. So, the question is: Is it possible to somehow cast

Re: [Haskell-cafe] Casting newtype to base type?

2013-07-01 Thread Frerich Raabe
. data P = P { a :: String, b :: String, c :: IOS } deriving (Show, Eq) but now when I try to set 'c' field in fun :: FilePath - P - IO P fun path p = do b - doesFileExist path ... return $ p {c = readFile path} I get error Couldn't match expected type `IOS

Re: [Haskell-cafe] Casting newtype to base type?

2013-07-01 Thread Tom Ellis
On Mon, Jul 01, 2013 at 05:07:00PM +0200, Vlatko Basic wrote: Hello Cafe! I had a (simplified) record data P = P { a :: String, b :: String, c :: IO String } deriving (Show, Eq) but to get automatic deriving of 'Show' and 'Eq' for 'data P' I have created 'newtype

Re: [Haskell-cafe] Casting newtype to base type?

2013-07-01 Thread Malcolm Wallace
' instances newtype IOS = IO String Not quite! That is a newtype'd String, not a newtype's (IO String). Try this: newtype IOS = IOS (IO String) but now when I try to set 'c' field in return $ p {c = readFile path} I get error Couldn't match expected type `IOS' with actual type `IO

Re: [Haskell-cafe] Casting newtype to base type?

2013-07-01 Thread Vlatko Basic
Hi Wallace, yes, indeed. Now I see I mixed newtype with type in declaration, and forgot the first one is a constructor. Original Message Subject: Re: [Haskell-cafe] Casting newtype to base type? From: Malcolm Wallace malcolm.wall...@me.com To: vlatko.ba...@gmail.com Cc

Re: [Haskell-cafe] Casting newtype to base type?

2013-07-01 Thread Vlatko Basic
I'm experimenting. The IO field is just a helper field, so it shouldn't have any consequences. Original Message Subject: Re: [Haskell-cafe] Casting newtype to base type? From: Tom Ellis tom-lists-haskell-cafe-2...@jaguarpaw.co.uk To: haskell-cafe@haskell.org Date: 01.07.2013

[Haskell-cafe] Geometric Algebra [Was: writing a function to make a correspondance between type-level integers and value-level integers]

2013-06-26 Thread oleg
It seems very interesting, but I have not currently the time to make a detailed comparison with vector/tensor algebra. Moreover I have not I would suggest the freely available Oersted Medal Lecture 2002 by David Hestenes

Re: [Haskell-cafe] homotopy type theory for amateurs

2013-06-26 Thread Ben
on how it is to be run. best, b On Jun 25, 2013, at 1:03 PM, Ben wrote: hello cafe -- by now i'm sure you have heard that the homotopy type theory folks have just written up a free introductory book on their project. http://homotopytypetheory.org/2013/06/20/the-hott-book/ gabriel

[Haskell-cafe] writing a function to make a correspondance between type-level integers and value-level integers

2013-06-25 Thread oleg
/ Geigen seems like a nice DSL that could well be embedded in Haskell. Anyway, the reason I pointed out Vectro is that it answers your question about reifying and reflecting type-level integers (by means of a type class). ___ Haskell-Cafe mailing list

[Haskell-cafe] homotopy type theory for amateurs

2013-06-25 Thread Ben
hello cafe -- by now i'm sure you have heard that the homotopy type theory folks have just written up a free introductory book on their project. http://homotopytypetheory.org/2013/06/20/the-hott-book/ gabriel gonzalez and i are starting up a small reading group for the book. the level

Re: [Haskell-cafe] writing a function to make a correspondance between type-level integers and value-level integers

2013-06-25 Thread TP
I have not your level of knowledge in Haskell/Standard ML and type theory, so I have already a lot of work. However, for sure this is something I will do in the few next years, because I think that notations are very important in physics and mathematics: it is of huge interest to have

Re: [Haskell-cafe] Fwd: How to make this data type work?

2013-06-23 Thread Magicloud Magiclouds
Thank you guys. I cannot use a explicit type for there are quite a few of them. But from MigMit, I understand why my original cannot work. On Sat, Jun 22, 2013 at 4:46 AM, Vincent Ambo taz...@gmail.com wrote: Is there a reason why you can't use an explicit type variable? {-# LANGUAGE

Re: [Haskell-cafe] writing a function to make a correspondance between type-level integers and value-level integers

2013-06-22 Thread TP
already offered. For example, the Vectro library has been described back in 2006: http://ofb.net/~frederik/vectro/draft-r2.pdf http://ofb.net/~frederik/vectro/ The paper also talks about reifying type-level integers to value-level integers, and reflecting them back. Recent GHC

[Haskell-cafe] How to make this data type work?

2013-06-21 Thread Magicloud Magiclouds
data ActionData = AD { oldData :: (FromJSON j, ToJSON j) = j , newData :: (FromJSON j, ToJSON j) = j} instance ToJSON ActionData where toJSON (AD o n) = object [ oldData .= o , newData .= n ] instance FromJSON ActionData where parseJSON

[Haskell-cafe] Fwd: How to make this data type work?

2013-06-21 Thread Miguel Mitrofanov
have to decide what j to use when serializing. Haskell won't automagically substitute some suitable type for you. So, that's a classic mismatch: for serializing (ToJSON) you need your j type to be known to the AD value (meaning: it should be quantified existentially), but for deserializing you

Re: [Haskell-cafe] Fwd: How to make this data type work?

2013-06-21 Thread Vincent Ambo
Is there a reason why you can't use an explicit type variable? {-# LANGUAGE OverloadedStrings, ExistentialQuantification #-} import Data.Aeson import Control.Applicative import Control.Monad (mzero) data ActionData j = (FromJSON j, ToJSON j) = AD j j instance ToJSON (ActionData j) where

Re: [Haskell-cafe] opengl type confusion

2013-06-17 Thread Tom Ellis
) is still requried on the first to fix the type there. How else could the compiler know that you mean 0.0 to be a GLdouble and not a GLfloat? it's curious that (0.0::GLdouble) 0.0 0.0 is good enough and that (0.0::GLdouble) (0.0::GLdouble) (0.0::GLdouble) is not required. I

[Haskell-cafe] writing a function to make a correspondance between type-level integers and value-level integers

2013-06-17 Thread oleg
, the Vectro library has been described back in 2006: http://ofb.net/~frederik/vectro/draft-r2.pdf http://ofb.net/~frederik/vectro/ The paper also talks about reifying type-level integers to value-level integers, and reflecting them back. Recent GHC extensions (like DataKinds) make

[Haskell-cafe] opengl type confusion

2013-06-16 Thread briand
() and using (0.0::GLdouble) fixes it, and I'm not clear on why it's not automagic. There are many times I see the compiler doing type conversion an numerican arguments although sometimes the occasional fracSomethingIntegralorOther is required. I was hoping for some enlightenment. Thank you. Brian

Re: [Haskell-cafe] opengl type confusion

2013-06-16 Thread Brandon Allbery
; if it expects GLdouble, it expects GLdouble. Pretending it's Double will not work. It would in the specific case that GLdouble were actually a type synonym for Double; however, for performance reasons it is not. Haskell Double is not directly usable from the C-based API used by OpenGL, so GLdouble

Re: [Haskell-cafe] opengl type confusion

2013-06-16 Thread briand
. There are many times I see the Haskell never automagics types in that context; if it expects GLdouble, it expects GLdouble. Pretending it's Double will not work. It would in the specific case that GLdouble were actually a type synonym for Double; however, for performance reasons

Re: [Haskell-cafe] opengl type confusion

2013-06-16 Thread L Corbijn
a type synonym for Double; however, for performance reasons it is not. Haskell Double is not directly usable from the C-based API used by OpenGL, so GLdouble is a type synonym for CDouble which is. compiler doing type conversion an numerican arguments although sometimes the occasional

Re: [Haskell-cafe] opengl type confusion

2013-06-16 Thread Tom Ellis
it Vertex3 takes three arguments, all of which must be of the same instance of VertexComponent. Specifying GLdoubles in the signature of wireframe specifies the types in the last three calls to Vertex3, but (0.0 :: GLdouble) is still requried on the first to fix the type there. How else could

Re: [Haskell-cafe] opengl type confusion

2013-06-16 Thread Brandon Allbery
::GLdouble) fixes it, and I'm not clear on why it's not automagic. There are many times I see the I presume the reason the type specification for numeric literals is because there is no defaulting (and probably can't be without introducing other strange type issues) for GLdouble. What I

Re: [Haskell-cafe] opengl type confusion

2013-06-16 Thread L Corbijn
. -- Forwarded message -- From: L Corbijn aspergesoe...@gmail.com Date: Mon, Jun 17, 2013 at 12:07 AM Subject: Re: [Haskell-cafe] opengl type confusion To: bri...@aracnet.com On Sun, Jun 16, 2013 at 11:10 PM, L Corbijn aspergesoe...@gmail.com wrote: On Sun, Jun 16, 2013 at 10:42 PM, bri

Re: [Haskell-cafe] opengl type confusion

2013-06-16 Thread briand
three calls to Vertex3, but (0.0 :: GLdouble) is still requried on the first to fix the type there. How else could the compiler know that you mean 0.0 to be a GLdouble and not a GLfloat? Tom it's curious that (0.0::GLdouble) 0.0 0.0 is good enough and that (0.0::GLdouble) (0.0

Re: [Haskell-cafe] writing a function to make a correspondance between type-level integers and value-level integers

2013-06-10 Thread TP
Richard Eisenberg wrote: without ScopedTypeVariables, the n that you would put on your annotation is totally unrelated to the n in the instance header, but this is benign becau se GHC can infer the type anyway. With ScopedTypeVariables, the `n`s are the same, which luckily agrees

[Haskell-cafe] writing a function to make a correspondance between type-level integers and value-level integers

2013-06-09 Thread TP
Hi all, Following a discussion on Haskell-Cafe, Richard E. made the following proposition of a Singleton to make a correspondance between type-level integers and value-level integers: data SNat :: Nat - * where SZero :: SNat 'Zero SSucc :: SNat n - SNat ('Succ n) (found at [1

Re: [Haskell-cafe] writing a function to make a correspondance between type-level integers and value-level integers

2013-06-09 Thread Richard Eisenberg
Hi TP, Here is slightly edited code that works: {-# LANGUAGE GADTs #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE ScopedTypeVariables #-} -- type level integers data Nat = Zero | Succ Nat deriving ( Show, Eq, Ord

Re: [Haskell-cafe] writing a function to make a correspondance between type-level integers and value-level integers

2013-06-09 Thread TP
of passing an argument, as you were trying, you set the type of a proxy using an explicit type annotation. Indeed I did not realize that I could use `P::Proxy n`, and so that n does not need to be argument of the data constructor `P`. - I added the extension ScopedTypeVariables, which allows

Re: [Haskell-cafe] writing a function to make a correspondance between type-level integers and value-level integers

2013-06-09 Thread Richard Eisenberg
. This is because my code was (unintentionally) slightly redundant. Here is the relevant code: instance MkSNat n = MkSNat (Succ n) where mkSNat _ = SSucc (mkSNat ???) What could possibly go in `???`? As in, what is the required type of that expression? We know mkSNat :: forall m. MkSNat m

Re: [Haskell-cafe] Typeable typeclass and type-level naturals

2013-06-06 Thread José Pedro Magalhães
Hi, On Wed, Jun 5, 2013 at 11:21 PM, TP paratribulati...@free.fr wrote: José Pedro Magalhães wrote: Oh, it should probably be simply deriving instance Typeable 'Zero deriving instance Typeable 'Succ Yes, that's how it should be. Please let me know if that doesn't work.

  1   2   3   4   5   6   7   8   9   10   >