ertes 2017-01-29 07:45:13
vimalloc_: write Int instead of i
monochrom 2017-01-29 07:45:33
oh heh
monochrom 2017-01-29 07:45:50
"Couldn't match expected type 'Int' with actual type 'i'" is actually meaningful.
ertes 2017-01-29 07:46:05
vimalloc_: your length type is Int, but your type signature in the first function claims that your function works for *any* length type, which is clearly not true
kadoban 2017-01-29 07:46:25
vimalloc_: In the second attempt there, Int isn't a typeclass, it's an actual type. So you'd write :: Int -> [a] -> a there
vimalloc_ 2017-01-29 07:46:43
I thought the (Int i) => i ... would do that. I didn't realize I could pass an exact time directly there
vimalloc_ 2017-01-29 07:46:46
Thx guys <3
monochrom 2017-01-29 07:47:06
And there is no such thing as "Int i".
ertes 2017-01-29 07:47:07
vimalloc_: types and type classes aren't the same thing… they aren't interchangable like that
vimalloc_ 2017-01-29 07:47:54
Could I do the same code with typeclasses (Just out of curiosity)? Something like (Num i, Ord i, Eq i) => i -> ..
kadoban 2017-01-29 07:47:59
You could almost write Num i => i -> [a] -> a but it wouldn't quite work, because 'length' gives you exactly an Int as a result, not any Num you want.
monochrom 2017-01-29 07:48:08
Not for this one. length insists on Int.
ertes 2017-01-29 07:48:10
vimalloc_: the definition doesn't permit it
vimalloc_ 2017-01-29 07:48:28
Great. Thanks!
monochrom 2017-01-29 07:48:35
Unless you throw in a bunch of "fromIntegral"s to relax it.
ertes 2017-01-29 07:51:59
vimalloc_: it's useful to keep in mind that whenever you write a type variable (without class constraints like Num), it can stand for *any* type… for example your function would have to be prepared to work with (i = Integer -> Rational) just as well as (i = Int)
monochrom 2017-01-29 07:53:11
No no, "any" alone is beside the point. But point is: from whose perspective.
monochrom 2017-01-29 07:53:19
Answer: From the user's perspective.
vimalloc_ 2017-01-29 08:02:36
o
PanosAsproulis[m 2017-01-29 08:06:20
Why does this fail?
PanosAsproulis[m 2017-01-29 08:06:47
Couldn't match expected type 'a' with actual type 'Triangle'
PanosAsproulis[m 2017-01-29 08:06:47
'a' is a rigid type variable bound by
PanosAsproulis[m 2017-01-29 08:07:08
Couldn't match expected type 'a' with actual type 'Triangle'
PanosAsproulis[m 2017-01-29 08:07:09
'a' is a rigid type variable bound by
PanosAsproulis[m 2017-01-29 08:07:44
the type signature for:
PanosAsproulis[m 2017-01-29 08:07:45
formingFaces :: forall a. Face a => Duo -> [a]
lyxia 2017-01-29 08:08:18
PanosAsproulis[m: in the last line you return a list of Triangles
pikajude 2017-01-29 08:08:22
PanosAsproulis[m: [t1 d, t2 d] :: [Triangle]
pikajude 2017-01-29 08:08:31
you need a forall a. Face a => [a]
PanosAsproulis[m 2017-01-29 08:08:44
Because Triangle is an instance of Face
pikajude 2017-01-29 08:08:58
it's true
PanosAsproulis[m 2017-01-29 08:09:03
Can I not use a Triangle for Face?
pikajude 2017-01-29 08:09:06
but it's not any a for which an instance of Face exists. it's Triangle
PanosAsproulis[m 2017-01-29 08:09:55
I don't understand.
kjslag 2017-01-29 08:10:37
I think you want: class Face a => Cell c a where formingFaces :: c -> [a]
lyxia 2017-01-29 08:10:48
Face a => c -> [a] means that the caller of formingFaces gets to pick the face type.
lyxia 2017-01-29 08:11:05
But then if you return a list of Triangle, it can't be any other face
PanosAsproulis[m 2017-01-29 08:12:59
But class Face a => Cell c a is like saying that Cell is a superclass of Face which is not meaningful
PanosAsproulis[m 2017-01-29 08:13:24
Sorry, Face is a superclass for Cell.
pikajude 2017-01-29 08:13:36
well, what are you trying to use Face for
PanosAsproulis[m 2017-01-29 08:14:37
Face should be unrelated to Cell. I just want a function that returns any kind of cell face.
pikajude 2017-01-29 08:15:09
that's my question. how are you using that information
ph88_ 2017-01-29 08:15:17
is it allowed to use | when manually giving the type with :: ?
PanosAsproulis[m 2017-01-29 08:16:08
The way it is in the code. There is no dependence of one on the other.
PanosAsproulis[m 2017-01-29 08:16:30
Also, the "class Face a => Cell c a where
PanosAsproulis[m 2017-01-29 08:16:31
formingFaces :: c -> [a]" gives me an error
PanosAsproulis[m 2017-01-29 08:16:45
Too many parameters for class 'Cell'
PanosAsproulis[m 2017-01-29 08:16:46
(Use MultiParamTypeClasses to allow multi-parameter classes)
kjslag 2017-01-29 08:17:00
You need to enable MultiParamTypeClasses in order to use my suggestion
kjslag 2017-01-29 08:18:00
http://lpaste.net/351770
PanosAsproulis[m 2017-01-29 08:19:11
Yes, with this option it works
PanosAsproulis[m 2017-01-29 08:20:31
It feels strange to me. That I have to specify the kind of Face I use and make Cell have Face as a superclass.
ph88_ 2017-01-29 08:21:36
cocreature, i saw that at one point where i was using get that the compiler infered the wrong type, after i manually put :: the error went away. So now i'm adding manual types on everywhere where i use get, i hope it will speed up ghc too
PanosAsproulis[m 2017-01-29 08:22:36
What I am trying to do is this: Have a Face typeclass and a Cell typeclass. Then create instances of these typeclasses for various kinds of faces (Triangle, Quadrangle etc) and various kinds of Cells (Tetrahedron, Hexahedron etc).
PanosAsproulis[m 2017-01-29 08:23:09
So, I want to be able for any kind of cell to return the forming faces which could be of any type.
cocreature 2017-01-29 08:23:23
ph88_: compile times of > 1 hour really don't call for "small" optimizations such as adding explicit type signatures. there must be some deeper problem and I would try to find that before you spend time on other compile time optimizations
kjslag 2017-01-29 08:23:49
Then I think you need pikajude's suggestion
ertes 2017-01-29 08:24:12
ph88_: there are no technical reasons to use giant modules… you should split it up
ph88_ 2017-01-29 08:24:21
cocreature, when i remove half of my code i get soooo many errors, it will take a very very long time to do some kind of binary search on leaving code out and running ghc
PanosAsproulis[m 2017-01-29 08:24:27
For certain cases the faces can be of different kinds. So, a Pyramid has one Quadrangle and 4 Triangles.
kjslag 2017-01-29 08:24:29
Maybe read this: https://wiki.haskell.org/Existential_type
geekosaur 2017-01-29 08:25:13
PanosAsproulis[m, I suspect your problem is you're thinking of typeclasses as OOP. class Face a => Cell a does not express that Cell is a subclass; it expresses that Cells are composed of Faces
ertes 2017-01-29 08:25:17
ph88_: if you want to do this in a principled way, try to come up with a small core language you can express the rest in, then write a separate module for that language
ph88_ 2017-01-29 08:25:58
ertes, you mean building up the grammar bottom up ?
PanosAsproulis[m 2017-01-29 08:26:03
geekosaur: how can I then return a list of Face objects, each one of a different type e.g. Triangle, Quadrangle etc?
ertes 2017-01-29 08:26:38
ph88_: yes… look for code patterns that you can factor out
geekosaur 2017-01-29 08:27:03
actually, as written, you can't because the precise relationship specified there is that you have some type a that has both Cell and Face instances. that does not sound like what you are describing
ph88_ 2017-01-29 08:27:20
ertes, i've starting writing the parser top-down and been feeling it ever since :/
ertes 2017-01-29 08:27:34
ph88_: similar to how computing sums and products can be factored out as foldl'
geekosaur 2017-01-29 08:27:56
quite possibly you want Cell to be a record type, one of whose fields is a list of Face-s. but if the Face-s can have different types then you need to have Face be an ADT with data constructors representing the different face types
kjslag 2017-01-29 08:27:59
PanosAsproulis[m: this is probably a better reference: https://en.wikibooks.org/wiki/Haskell/Existentially_quantified_types#Example:_heterogeneous_lists
geekosaur 2017-01-29 08:28:08
(which will end up being much cleaner, but it's harder to extend in the future)
ph88_ 2017-01-29 08:28:09
ertes, i have little inside of how certain grammar rules are clustered together
ertes 2017-01-29 08:28:12
ph88_: yeah, as you see GHC *really* wants you to write functional code =)
geekosaur 2017-01-29 08:28:43
typeclasses for this kind of thing is a bit of a code smell
geekosaur 2017-01-29 08:29:03
(although there are ways to do it that can use typeclasses --- not the way you are trying to do it, though)
ertes 2017-01-29 08:29:25
ph88_: my first step would be to look for code patterns that are similar
PanosAsproulis[m 2017-01-29 08:29:34
geekosaur: Thank you. I will read the link.
ertes 2017-01-29 08:29:51
ph88_: if you really can't find any (unlikely in 4K LoC), then try to *make them* look similar
geekosaur 2017-01-29 08:30:18
and heterogeneous lists are also a bit of a code smell, not to mention a massive PITA to work with; try to find a different way to represent it
ph88_ 2017-01-29 08:30:21
ertes, well i suppose when i want to redo this bottom up i can take all the rules that only contain terminals and start building on top of them ^^
ertes 2017-01-29 08:31:14
ph88_: i don't know your use case, so i can't really give you a strategy, but the idea is very similar to things like foldr
ertes 2017-01-29 08:31:30
pretty much all single-list reductions are foldrs
ertes 2017-01-29 08:31:50
once you really understand foldr, you see them everywhere and start expressing them in terms of foldr
ph88_ 2017-01-29 08:31:57
not sure how fold relates to this tbh .. i'm thinking about grammar rules and types
kjslag 2017-01-29 08:31:57
I have some questions about profiling with GHC using set cost centers (SCC).
ertes 2017-01-29 08:31:58
(or special cases of it)
kjslag 2017-01-29 08:32:04
For example, is it possible to manually attach an SCC to an entire function? For example, how do I attach an SCC to "f x = g x where g = ..."? If I write "f x = {-# SCC f #-} g x where g = ...", then the "where g = ..." part isn't included in the SCC. Somehow, -fprof-auto seems to be able to attach an SCC to all of "f" at once, which is what I want to do manually.
ertes 2017-01-29 08:32:44
ph88_: well, i can give you an exercise, if you want
geekosaur 2017-01-29 08:32:46
the big problem with what you were doing is that the most sensible use case for it is (Face f, Structure s) => class Cell s f where type CFace s = f; ... -- which limits you to one type of face
ph88_ 2017-01-29 08:32:50
the amount of errors i find by just reading my own code is also staggering :|
ph88_ 2017-01-29 08:32:56
ertes, sure :P
ph88_ 2017-01-29 08:33:09
but it will take a few minutes before i have my hands free
ph88_ 2017-01-29 08:33:24
i'm trying to get another run of ghc and see if it works better with a lot of things type annotated
ertes 2017-01-29 08:34:07
ph88_: three steps: 1. implement (++) naively (not using combinators), 2. implement a function that prints each element of its argument list (again without combinators like 'traverse'), 3. find a common pattern and factor it out
geekosaur 2017-01-29 08:38:10
PanosAsproulis[m, btw another way to do this is to break Face down, rather than have Triangle, Quadrangle, etc. have data Face = Face {vertices :: Int; conns :: [Double {- angles -} ]};
geekosaur 2017-01-29 08:38:26
or something like that
geekosaur 2017-01-29 08:40:15
or if the angles need to be in the Cell then Face would just have vertices and quadrangle = Face {vertices = 4}
geekosaur 2017-01-29 08:40:48
but I'd have to know more about what you are modeling and what you're trying to do with it to give a better description
geekosaur 2017-01-29 08:41:22
(for example you might do better with edges instead of vertices)