BernhardPosselt 2017-02-06 09:46:54
ok, a bit further :) http://dpaste.com/1P3Z4SW
BernhardPosselt 2017-02-06 09:47:01
Ambiguous type variable 'a0' arising from a use of 'show' prevents the constraint '(Show a0)' from being solved.
BernhardPosselt 2017-02-06 09:47:09
why does this happen?
BernhardPosselt 2017-02-06 09:47:46
isnt a a type that is required to implement Show when looking at the constraint?
hexagoxel 2017-02-06 09:48:23
BernhardPosselt: compiler does not know which dictionary not to use there :)
BernhardPosselt 2017-02-06 09:49:09
dictionary?
EvanR 2017-02-06 09:49:20
BernhardPosselt: when you see ambiguous type error, it means inference cant know which type you want, and it matters which one you pick
EvanR 2017-02-06 09:49:32
> read "()" :: ()
lambdabot 2017-02-06 09:49:35
()
EvanR 2017-02-06 09:49:41
> read "5" :: Int
lambdabot 2017-02-06 09:49:44
5
EvanR 2017-02-06 09:49:49
> read "()" :: Int
lambdabot 2017-02-06 09:49:51
*Exception: Prelude.read: no parse
BernhardPosselt 2017-02-06 09:50:23
is it because i only use Nil?
Xnuk 2017-02-06 09:50:30
> readMay "()" :: Maybe ()
lambdabot 2017-02-06 09:50:33
error:
lambdabot 2017-02-06 09:50:33
Variable not in scope: readMay :: [Char] -> Maybe ()
BernhardPosselt 2017-02-06 09:50:37
so the compiler can not deduce the type for the second show clause?
BernhardPosselt 2017-02-06 09:50:44
deduct*
BernhardPosselt 2017-02-06 09:51:46
putStrLn $ show (Node Nil 5 Nil)
BernhardPosselt 2017-02-06 09:51:47
works
BernhardPosselt 2017-02-06 09:51:58
so i guess thats the issue
EvanR 2017-02-06 09:52:20
BernhardPosselt: putStrLn . show = print
hexagoxel 2017-02-06 09:52:24
BernhardPosselt: yeah, pretty much. It could be any a, so it does not know which (Show a) dictionary to use.
hexagoxel 2017-02-06 09:53:06
and the second show clause is even relevant, the (Show a) => .. part is.
reactormonk 2017-02-06 09:53:48
ertes, neat, good to know, thanks.
hexagoxel 2017-02-06 09:53:55
although only the second class that does use the dictionary, of course. but if it did not, and you still had the Show a, you'd still have the same problem.
dolio 2017-02-06 09:53:57
It won't choose one for you for `Show a`. The reason why putting the 5 in work is that it will choose something for `Num a`.
sternmull 2017-02-06 09:53:58
BernhardPosselt: When you give the compiler a "Nil" then you use a constructor where the typ "a" is not bound to anything. So he can not know what kind of Tree that should exactly be. And it needs that information to know what to do for the second show implementation.
BernhardPosselt 2017-02-06 09:54:17
what happens if you want to write a library?
BernhardPosselt 2017-02-06 09:54:36
do you need to add generic type signatures?
BernhardPosselt 2017-02-06 10:01:41
ok got it :)
BernhardPosselt 2017-02-06 10:01:46
works just fine without usage
BernhardPosselt 2017-02-06 10:01:49
putStrLn $ show (Nil :: Tree String)
hexagoxel 2017-02-06 10:03:05
> show []
lambdabot 2017-02-06 10:03:08
"[]"
barrucadu 2017-02-06 10:05:15
How come that works? Defaulting rules?
hexagoxel 2017-02-06 10:05:26
this works due to defaulting. i think you could add a defaulting declaration for Tree (), but i don't think it is common to do that.
EvanR 2017-02-06 10:05:37
> read "[()]"
lambdabot 2017-02-06 10:05:40
*Exception: Prelude.read: no parse
EvanR 2017-02-06 10:06:07
doh
EvanR 2017-02-06 10:06:33
hexagoxel: defaulting of what class?
hexagoxel 2017-02-06 10:06:54
> map id (read "[()]")
lambdabot 2017-02-06 10:06:56
[()]
hexagoxel 2017-02-06 10:07:45
needs to know that it is [_] at least :)
BernhardPosselt 2017-02-06 10:08:14
regarding the deriving stuff: does this work similar like Rust's derive attribute/macro? e.g. #[derive(Debug)]
BernhardPosselt 2017-02-06 10:08:40
#[derive(Show)]
BernhardPosselt 2017-02-06 10:08:46
its even the same name :D
EvanR 2017-02-06 10:09:04
having to derive Show is really annoying, its often the only thing i derive
EvanR 2017-02-06 10:09:11
i wish it was automagic
EvanR 2017-02-06 10:09:23
at least for types that make sense
BernhardPosselt 2017-02-06 10:09:25
does it use macros internally?
EvanR 2017-02-06 10:09:30
but possibly for types that dont make sense
BernhardPosselt 2017-02-06 10:09:31
to generate code?
EvanR 2017-02-06 10:09:44
no, its built into the language
EvanR 2017-02-06 10:10:17
there are no macros, but there is template haskell
hexagoxel 2017-02-06 10:16:38
ah, the reason show [] works is because of ExtendedDefaultRules, not because of anything []-specific.
hexagoxel 2017-02-06 10:16:51
and show Nil would work with Extended~.
hexagoxel 2017-02-06 10:16:57
(right?)
dolio 2017-02-06 10:17:05
Yes.
urban24 2017-02-06 10:20:30
Hi, getting the wronh sha when donloading
urban24 2017-02-06 10:20:40
0124399b1bbad2e5f615dbccc49df69db02fbe37d9e500378b59101c244b41e1 haskell-platform-8.0.2-unknown-posix--full-x86_64.tar.gz
urban24 2017-02-06 10:21:03
from https://www.haskell.org/platform/#linux-generic
ph88 2017-02-06 10:22:16
hey guys, i'm making a parser and i have a rule for Identifier this should be followed by whitespace depending on the context where Identifier is used. Should i store the whitespace in the context? I think if i put the whitespace with the Identifier that it will cause problems when i start moving Identifier's around and place them in new contexes
urban24 2017-02-06 10:22:28
web page say: c68a6f278a192d5000e8feefb0e63cef1bd441d02b84602984
dolio 2017-02-06 10:22:52
urban24: Your hash looks longer.
ph88 2017-02-06 10:23:07
before i was storing all the whitespace after a token in the type of that token itself .. now i'm breaking this pattern and it feels a bit strange
dolio 2017-02-06 10:23:07
Maybe it's a different hash?
urban24 2017-02-06 10:23:43
it should be a sha256
hexagoxel 2017-02-06 10:23:46
website says c68a6f278a192d5000e8feefb0e63cef1bd441d02b846029840b98a5fa3ee31a; it does some bad linebreak.
urban24 2017-02-06 10:24:30
ahh, missed the page brake, sorry
urban24 2017-02-06 10:24:56
but it's still not the same :-(
qmm 2017-02-06 10:25:17
where would hoogle be installed if i ran `cabal install hoogle`?
qmm 2017-02-06 10:25:29
i've ran this, but i don't see a ~/.cabal/bin dir
hexagoxel 2017-02-06 10:25:35
urban24: i see the same hash as you. maybe ask in #haskell-infrastructure too.
urban24 2017-02-06 10:25:49
ok, thanks
geekosaur 2017-02-06 10:27:41
qmm, did you install it in a sandbox? if so, it's in the sandbox bin directory (.cabal-sandbox/bin iirc)
qmm 2017-02-06 10:28:05
geekosaur: i wish i did
qmm 2017-02-06 10:28:12
there isn't a .cabal-sandbox/bin
qmm 2017-02-06 10:28:47
nor a .cabal-sandbox
BernhardPosselt 2017-02-06 10:28:51
when pattern matching in haskell, is there a way to refer to a container? e.g. show (Node left value right) basically extracts left, value and right, but how do i get the whole thing inside the parenthesis?
geekosaur 2017-02-06 10:29:10
BernhardPosselt, somename@(...)
geekosaur 2017-02-06 10:29:18
"as-pattern"
BernhardPosselt 2017-02-06 10:29:20
ty
BernhardPosselt 2017-02-06 10:39:37
is there a built in way to find the first Just a in a list of Maybe a?
BernhardPosselt 2017-02-06 10:39:58
or Nothing if everything in the list is Nothing
BernhardPosselt 2017-02-06 10:40:24
i've found find but i dont really know how to define the predicate
kadoban 2017-02-06 10:40:35
I think that's listToMaybe . catMaybes
nil_ 2017-02-06 10:40:38
I think you can do it using Alternative
jle` 2017-02-06 10:41:24
BernhardPosselt: there's asum
dmwit 2017-02-06 10:41:26
:t find
lambdabot 2017-02-06 10:41:27
Foldable t => (a -> Bool) -> t a -> Maybe a
jle` 2017-02-06 10:41:38
> asum [Nothing, Nothing, Just 10, Nothing, Just 20]
lambdabot 2017-02-06 10:41:41
Just 10
BernhardPosselt 2017-02-06 10:41:48
ty
jle` 2017-02-06 10:41:53
also `foldMap First` i suppose
jle` 2017-02-06 10:42:04
> foldMap First [Nothing, Nothing, Just 10, Nothing, Just 20]
lambdabot 2017-02-06 10:42:07
First {getFirst = Just 10}
dmwit 2017-02-06 10:42:07
jle`++
jle` 2017-02-06 10:42:32
BernhardPosselt: no problem!
BernhardPosselt 2017-02-06 10:42:47
asum as in alternative sum?
pikajude 2017-02-06 10:42:59
:t asum
lambdabot 2017-02-06 10:43:01
(Alternative f, Foldable t) => t (f a) -> f a
nil_ 2017-02-06 10:43:17
jle`: nice!
jle` 2017-02-06 10:43:19
BernhardPosselt: yeah, sum [x,y,z] = x <|> y <|> z <|> empty
pikajude 2017-02-06 10:43:22
incidentally, i use Dash the osx documentation browser for searching haddocks on mac, but i've found no comparable solution on linux
pikajude 2017-02-06 10:43:28
does anyone have a recommendation?
jle` 2017-02-06 10:43:32
so it's like mconcat, but wiht <|> instead of <>
jle` 2017-02-06 10:44:16
a lot of people believe that Maybe's Monoid instance should really be <|>/Firsty ... if that was teh case you could have just done 'mconcat'
pikajude 2017-02-06 10:44:55
does that fulfill the laws?
jle` 2017-02-06 10:45:06
yup, there's actually a newtype wrapper that providesthat instance, First