Search Haskell Channel Logs

Friday, February 24, 2017

#haskell channel featuring LordBrain, merijn, lyxia, Bish, yushyin, liste, and 8 others.

bpa2 2017-02-23 23:59:24
I started with Haskell a couple of days ago and am working through Learn You a Haskell...the first example in Syntax in Functions gives lucky :: (Integral a) => a -> String as the function signiture. Why is Integral the typeclass? As opposed to Num for example. I have tried using Num and it produces errors - but why? In the third examle the signiture is factorial :: (Integral a) => a -> a. Again with Integral. Why? factorial could have
bpa2 2017-02-24 00:00:41
The last part of my question should be:Again with Integral. Why? factorial could have a simple factorial :: Int -> Int as the signiture so why use the typeclass Integral? Is there a newbie friendly chart showing the hierarchy of number typeclasses and types?
Ferdirand 2017-02-24 00:02:10
Num alone would not be enough to define a factorial, I think
quchen 2017-02-24 00:02:19
bpa2: There is one in the Haskell Report. The Haskell number class hierarchy is fairly messy, but in practice you rarely need more than Num and sometimes Integral. https://www.haskell.org/onlinereport/classes.gif
quchen 2017-02-24 00:02:41
bpa2: Num gives you + - *, Integral adds div/mod ontop of that.
quchen 2017-02-24 00:02:50
That's the basic summary. :-)
Ferdirand 2017-02-24 00:03:02
Integral also implicitely adds Enum
Ferdirand 2017-02-24 00:03:15
that you would need if you used the [a..b] notation
quchen 2017-02-24 00:04:39
bpa2: GHC infers the most general type for your expressions, not just »one that works«. Your function works for anything Integral, so GHC will not give you the specialized Int version of that.
Ferdirand 2017-02-24 00:04:58
Num gives you a way to subtract 1, but you would still need to test for equality
av_ 2017-02-24 00:05:14
bpa2: you could restrict the type to Int -> Int, but that would remove polymorphism altogether, and wouldn't be a good choice anyway because factorial can reach the maxBound of Int fairly quickly -- use Integer instead, if you really need a monomorphic function
av_ 2017-02-24 00:06:17
bpa2: the minimum set of type classes you need to specify (unless you omit the type declaration altogether) depends on the operations you use in your definition
Ferdirand 2017-02-24 00:06:27
and by the way, you can use :info in ghci to get info about typeclass definitions
av_ 2017-02-24 00:07:25
bpa2: as a hint, omit the type class, then run ghc on it with -Wall, that will give you a general (or even the most general?) type definition in its warnings
av_ 2017-02-24 00:08:14
bpa2: newer GHCs even warn of redundant class constraints, which is very useful sometimes
bpa2 2017-02-24 00:08:57
Thank you guchen and Ferdirand...yes I see its not just the type of number but the operations that can be performed on them! Wow av that would be a big factorial - but yes I get your point.
bpa2 2017-02-24 00:11:52
Thank you for directing me to the chart guchen!
Bish 2017-02-24 00:15:25
hi, when people are talking about "creating DSLs in haskell to not have to write haskell at all" what do they mean by it
Bish 2017-02-24 00:15:38
does that always mean, parsing bytestrings ors imiliar in runtime, to express what you want to do?
pacak 2017-02-24 00:17:12
Bish: Look at xmonad config. I make my first one long before I was able to program in haskell.
Bish 2017-02-24 00:17:13
if so: why is this considered so great in haskell, i mean you always have the overhead of interpreting your own language
Bish 2017-02-24 00:18:35
i think i've seen something like that when playing with awesome?
Bish 2017-02-24 00:18:39
i hated it :D
liste 2017-02-24 00:19:12
yes, awesome has Lua as config language
Bish 2017-02-24 00:19:30
really? okay, then i was using xmonad
pacak 2017-02-24 00:19:34
I'm still using more or less the same config. The only difference is that I know what those things mean,.
Bish 2017-02-24 00:19:36
i am sure it was haskell
Bish 2017-02-24 00:20:03
but still.. i don't quite understand, if i am parsing my own language in runtime, doesn't that make a lot of overhead?
Tuplanolla 2017-02-24 00:20:25
It's usually compiled, Bish.
Bish 2017-02-24 00:21:15
how do i compile my own language? that's the thing i don't get
Bish 2017-02-24 00:21:31
i mean, can i tell haskell how to compile my dsl and integrate it into my binary, or whats the deal?
Tuplanolla 2017-02-24 00:23:04
I mean the usual way is to put the language into a Haskell library and have GHC compile it like the rest of your code. It's not really a separate language on its own.
Tuplanolla 2017-02-24 00:23:34
Some projects diverge from this and interpret or compile such languages at runtime.
pacak 2017-02-24 00:23:42
One approach - xmonad. You can also write a parser with parsec and write some interpreter for resulting AST
liste 2017-02-24 00:23:43
Bish: if you want to modify the behaviour at runtime, you'd of course compile/parse it at runtime, and if you want compile time, you can use eDSLs or TH, for example
Bish 2017-02-24 00:24:13
so there is a way, so my dsl gets compiled to assembler, too?
lyxia 2017-02-24 00:24:51
It's easy if it's an eDSL
Bish 2017-02-24 00:25:11
e as in embedded?
Bish 2017-02-24 00:25:15
so that's the thing i need to google
liste 2017-02-24 00:25:17
yes
Bish 2017-02-24 00:25:37
so i kinda can write my own language in haskell, and use it inside haskell?
Bish 2017-02-24 00:25:45
that'd be interesting
Tuplanolla 2017-02-24 00:25:59
Are you familiar with Scheme, Bish?
Bish 2017-02-24 00:26:02
no
Tuplanolla 2017-02-24 00:26:26
They've done the same thing for much longer and more comprehensively.
Bish 2017-02-24 00:26:53
Tuplanolla: thanks looking into it
liste 2017-02-24 00:26:59
here's an example of an eDSL: https://hackage.haskell.org/package/lucid
Bish 2017-02-24 00:27:21
what started my interest in that is a ORM that expresses SQL very convieniently
Bish 2017-02-24 00:27:28
i decided i want to see more of that
Bish 2017-02-24 00:27:45
that one was in ruby, which has these weird block "DSLs"
Bish 2017-02-24 00:28:13
which kinda looks like programming via configurations, i really liked that and searching for a language which does that more natively, thought haskell might be this one language
Bish 2017-02-24 00:28:17
looking at scheme now
liste 2017-02-24 00:29:03
scheme is even more flexible eDSL-wise, but with Haskell you get more "for free"
liste 2017-02-24 00:29:17
type checking, tools, etc
liste 2017-02-24 00:29:53
racket, a scheme-based language, is even more dsl-oriented than scheme
Bish 2017-02-24 00:30:28
but when looking at lucid, it doesn't look much like a dsl
Bish 2017-02-24 00:30:38
i mean, that's just haskell syntax
Bish 2017-02-24 00:30:39
isn't it?
liste 2017-02-24 00:31:11
Bish: it is Haskell, that's what edsls are, a "language within a language"
Bish 2017-02-24 00:31:31
well, what makes it it's own languagte than
Bish 2017-02-24 00:31:42
i would call that domain specific expressions
Bish 2017-02-24 00:31:59
i was hoping for something that "wraps" that
Tuplanolla 2017-02-24 00:32:01
I would prefer that name.
Bish 2017-02-24 00:32:56
aww :( i wished that all would be so much cooler
Bish 2017-02-24 00:34:35
i was kinda hoping that you can do something like.. express something like jade inside a haskell sourcefile, what then gets wrapped by haskell, then compiled, and be fast, beauty and optimizeable
alexbiehl 2017-02-24 00:34:51
Bish: take a look at QuasiQuoters
Tuplanolla 2017-02-24 00:35:08
@hackage inline-java
lambdabot 2017-02-24 00:35:08
http://hackage.haskell.org/package/inline-java
alexbiehl 2017-02-24 00:35:25
A nice blog post on that topic: https://www.well-typed.com/blog/2014/10/quasi-quoting-dsls/
liste 2017-02-24 00:35:29
Bish: that's done too, extensively by the Yesod framework
Bish 2017-02-24 00:35:46
that looks more like it
liste 2017-02-24 00:36:26
Bish: see http://www.yesodweb.com/book/shakespearean-templates#shakespearean-templates_interpolation for example
Bish 2017-02-24 00:36:38
so this code inside thesequasiquotations
Bish 2017-02-24 00:36:44
gets somehow translated to haskell
liste 2017-02-24 00:36:47
yes
Bish 2017-02-24 00:36:51
and will be optimizeable in compilation?
Bish 2017-02-24 00:36:55
thats just fucking great, isn't it?
liste 2017-02-24 00:37:12
it'll be just like any other piece of Haskell code
liste 2017-02-24 00:38:02
I think there's certain advantages to leveraging Haskell syntax instead of using quosiquotation though, if you have the option to specify a new language
Bish 2017-02-24 00:38:38
sure, this will have disadvantages, but still
Bish 2017-02-24 00:38:55
haskell is pretty ugly, but pretty great, if you could remove the most ugly parts with something like this
Bish 2017-02-24 00:39:01
would make it a lot better
Bish 2017-02-24 00:40:50
thanks for the insight, i will look into these things
yushyin 2017-02-24 00:41:02
Haskell isnt ugly at all :(
Bish 2017-02-24 00:41:16
it's sooo freakin ugly, :( but it's opinion
Tuplanolla 2017-02-24 00:41:22
Nonsense. It's a mess.
yushyin 2017-02-24 00:41:45
Ghc haskell is ugly :)
Bish 2017-02-24 00:41:56
imho it begins with .. postfix..infix.. whatever we do both whenever we want
LordBrain 2017-02-24 00:41:57
well, what about old school haskell98
LordBrain 2017-02-24 00:42:00
that was pretty
merijn 2017-02-24 00:42:15
What's ugly about GHC haskell?
Tuplanolla 2017-02-24 00:42:23
Even old Haskell has warts like the lack of `ArgumentDo`.
merijn 2017-02-24 00:42:43
Is ArgumentDo even a thing yet?
Tuplanolla 2017-02-24 00:42:54
No and that sucks.
LordBrain 2017-02-24 00:43:49
merijn, well... we have a slew of language pragragmas these days at the top of every program... our imports are a mile long typically.... and of course magic hash is not exactly aesthetic.. we have nice pretty sugar for lists, but use things like pipes and conduits instead, and then there's dependent type foo
LordBrain 2017-02-24 00:44:13
i love haskell... don't get me wrong...
LordBrain 2017-02-24 00:44:39
but it's value on prettiness has gone down significantly i think
LordBrain 2017-02-24 00:44:49
as peopel prioritize everything else i guess