glguy 2017-02-28 06:49:07
newtype Value = Value { ($$) :: Value -> Value } ; y = Value (\f -> f $$ (y $$ f))
wz1000 2017-02-28 06:50:59
glguy: That has both recursive types and values :)
glguy 2017-02-28 06:52:07
You didn't say anything about values, and the type isn't the one you excluded!
wz1000 2017-02-28 06:52:53
wz1000 | I remember seeing a non-recursive(in type or value) implementation of the y combinator. Does anyone know of what I am talking about?
wz1000 2017-02-28 06:53:03
glguy: ^
glguy 2017-02-28 06:53:06
OK
sternmull 2017-02-28 06:54:32
i made a bash-like "brace expansion" for strings: http://lpaste.net/353065 it would be nice if someone could comment on it. Did i do any stupid unnecessary/complicated things?
sm 2017-02-28 07:00:54
looks reasonable sternmull
sternmull 2017-02-28 07:03:34
oh nice :) Would you do it like this in production code (except for replacing String with Text)? Or would you use something like Parsec instead?
ertes 2017-02-28 07:05:25
sternmull: i would abstract Char away
ertes 2017-02-28 07:05:28
in practice
ertes 2017-02-28 07:06:01
sternmull: but more likely i would just use the monadic interface to []
ertes 2017-02-28 07:06:57
@let (<++>) = liftA2 (++)
sternmull 2017-02-28 07:06:58
Can i abstract Char? How does that work with '}' and ',' as literals in the code?
lambdabot 2017-02-28 07:07:00
Defined.
ertes 2017-02-28 07:07:42
> ["hello"] <++> ["!", "?"] <++> " i'm the " <++> ["girl", "guy"]
lambdabot 2017-02-28 07:07:45
error:
lambdabot 2017-02-28 07:07:45
• Couldn't match type 'Char' with '[Char]'
lambdabot 2017-02-28 07:07:45
Expected type: [[Char]]
ertes 2017-02-28 07:07:52
> ["hello"] <++> ["!", "?"] <++> [" i'm the "] <++> ["girl", "guy"]
lambdabot 2017-02-28 07:07:55
["hello! i'm the girl","hello! i'm the guy","hello? i'm the girl","hello? i'...
ertes 2017-02-28 07:08:13
also gives you a few things for free
leshow 2017-02-28 07:08:22
> :t (<++>)
lambdabot 2017-02-28 07:08:25
ertes 2017-02-28 07:08:32
> sequenceA ["h", "e3", "l", "lL", "o0"]
leshow 2017-02-28 07:08:34
what the heck is <++>
lambdabot 2017-02-28 07:08:34
["hello","hell0","helLo","helL0","h3llo","h3ll0","h3lLo","h3lL0"]
ertes 2017-02-28 07:08:42
leshow: i defined it above
leshow 2017-02-28 07:08:48
oh, missed that
sternmull 2017-02-28 07:09:12
ertes: Thanks. I will try to write another version that uses the list monad.
thoughtpolice 2017-02-28 07:09:22
Public announcement (since I just wrote it): Hackage will have a short maintenance window within a few hours. https://www.reddit.com/r/haskell/comments/5wpkhh/heads_up_short_hackage_downtime_today_30_minutes/ It shouldn't last very long.
sm 2017-02-28 07:10:36
thank you thoughtpolice
sm 2017-02-28 07:12:24
sternmull: in production code I'd probably do it exactly like that, and move on, until I had some need to make it smarter
sm 2017-02-28 07:14:59
ie, if it's working and reasonably easy to understand. I might add a one sentence description and an example to the main function
ertes 2017-02-28 07:17:37
> foldr (liftA2 (++)) [[]] [["abc"], ["def", "ghi"], ["jkl"]]
lambdabot 2017-02-28 07:17:40
["abcdefjkl","abcghijkl"]
sternmull 2017-02-28 07:18:09
sm: Ok. I had do this stuff today with python and did it a regex and a few lines around it. So i thought it would be a nice exercise to see how it would look in haskell. I think at the moment i have a similar linecount.
Onemorenickname_ 2017-02-28 07:18:23
hello people
Onemorenickname_ 2017-02-28 07:18:30
i don't haskell, but i'm reading https://arxiv.org/pdf/1512.01895.pdf
Onemorenickname_ 2017-02-28 07:18:41
it's written "For example, a
Onemorenickname_ 2017-02-28 07:18:41
Haskell program can only contain at most one instance of Show Int"
Onemorenickname_ 2017-02-28 07:19:11
does it mean that in 2 independant files, there can not be difference instances of Show Int ?
ertes 2017-02-28 07:19:23
Onemorenickname_: there can, but it's discouraged
Onemorenickname_ 2017-02-28 07:19:48
ertes, what's the rationale ?
glguy 2017-02-28 07:19:50
Onemorenickname_: That's correct, Haskell doesn't allow that
byorgey 2017-02-28 07:19:51
Onemorenickname_: well, there can be, but then you can never use those files together as part of the same program.
ertes 2017-02-28 07:19:59
Onemorenickname_: type classes in haskell follow the "open world" principle, which means that in general instances should be considered global and unique
Onemorenickname_ 2017-02-28 07:20:09
ertes, even for libraries ?
ertes 2017-02-28 07:20:13
Onemorenickname_: yes
Onemorenickname_ 2017-02-28 07:20:16
hm
Onemorenickname_ 2017-02-28 07:20:28
is there some doc on why the open world assumption is followed ?
Tuplanolla 2017-02-28 07:21:08
Imagine putting items with some `Ord` instance into a `Map` and consider what happens if you suddenly change that instance, Onemorenickname_.
ertes 2017-02-28 07:21:25
Onemorenickname_: it's both historical, and it establishes a notion of responsibility… an instance should be defined either at the definition site of the type or of the class
ertes 2017-02-28 07:21:43
Onemorenickname_: instances defined elsewhere we call "orphan instances", and they are discouraged for precisely that reason
Onemorenickname_ 2017-02-28 07:21:51
Tuplanolla, if you say from where the Ord instance comes, it's not really a problem. If you include two files defining "Ord", then I can see the problem
glguy 2017-02-28 07:22:20
ertes: GHC doesn't aggressively check for colliding orphans as a performance optimization, not as a way to sneak them in
Onemorenickname_ 2017-02-28 07:22:20
ertes : I see. and as the guideline is followed by the community, it's counter-productive to go against it
Tuplanolla 2017-02-28 07:22:31
You would need a mechanism for distinguishing instances then, Onemorenickname_.
ertes 2017-02-28 07:23:06
Onemorenickname_: the rationale is that for any potential instance there should be one particular semantics that everybody agrees on… different semantics are implemented by using wrapper types
glguy 2017-02-28 07:23:29
If two instances are in scope when resolving that constraint compilation will fail with an error
ertes 2017-02-28 07:23:36
> getAny . fold . map Any $ [True, False]
lambdabot 2017-02-28 07:23:39
True
ertes 2017-02-28 07:23:41
> getAll . fold . map All $ [True, False]
lambdabot 2017-02-28 07:23:43
False
ertes 2017-02-28 07:23:53
Any and All establish different monoids over Bool
glguy 2017-02-28 07:24:13
Onemorenickname_: Without this coherence property you can't be sure that each operation you define in terms of these instances will get the same instance for the same type
Tuplanolla 2017-02-28 07:24:14
Related: should I use `First` or `Alt Maybe`?
glguy 2017-02-28 07:24:20
so you can't rely on things like a consistent ordering
Cale 2017-02-28 07:24:23
It's worth noting that orphan instances are only a concern for *libraries*
ertes 2017-02-28 07:24:41
depending on which wrapper type you choose you get different 'mappend' semantics
johnw 2017-02-28 07:25:01
> ala Any foldMap [True, False]
lambdabot 2017-02-28 07:25:07
mueval-core: Time limit exceeded
johnw 2017-02-28 07:25:13
=> True
Cale 2017-02-28 07:25:17
If what you're producing is the final executable program, then there's no problem defining some orphan instances, because you have the last word on what conventions you want, and can't conflict with anyone else.
ertes 2017-02-28 07:25:45
Onemorenickname_: yeah, but more importantly it's not a limitation… you can still have different semantics for the same type, but the way you choose the semantics is by multiple types, not by multiple instances
ertes 2017-02-28 07:26:36
and a practical benefit, of course, is that inference doesn't need a lot of help
Cale 2017-02-28 07:26:38
Also, if you find yourself limited or annoyed by the fact that you can't define multiple instances of your class for the same type, you can always just switch to using a record datatype instead of a class.
leshow 2017-02-28 07:27:52
is the definition of traverse always equivalent to the Functor instance i some way? im noticing a pattern when writing traversable instances that it's just the Functor instance but with function application switched with <$> and <*> and fmap switched with traverse
glguy 2017-02-28 07:28:19
leshow: You can derive a Functor instance from a Traversable instance
glguy 2017-02-28 07:28:37
:t Data.Traversable.fmapDefault
lambdabot 2017-02-28 07:28:39
Traversable t => (a -> b) -> t a -> t b
leshow 2017-02-28 07:28:42
for instance, fmap f (Cons a fa) = Cons (f a) (fmap f fa), traverse f (Cons a fa) = Cons <$> f a <*> traverse f fa
glguy 2017-02-28 07:29:20
They're related in that if you choose Identity to be your Applicative for traverse you get fmap
johnw 2017-02-28 07:29:21
leshow: traverse is sequence . fmap
johnw 2017-02-28 07:29:29
so you're noticing the "fmap" part of that definition
leshow 2017-02-28 07:29:37
glguy, can you derive a foldable instance too
leshow 2017-02-28 07:29:41
from traversable
leshow 2017-02-28 07:29:49
it also seems similar in structure
glguy 2017-02-28 07:29:50
:t Data.Traversable.foldMapDefault
lambdabot 2017-02-28 07:29:53
(Monoid m, Traversable t) => (a -> m) -> t a -> m
leshow 2017-02-28 07:30:08
ah ok, the universe is starting to make sense
leshow 2017-02-28 07:30:18
i was like damn these look really similar somehow
glguy 2017-02-28 07:30:24
Which is why: class (Functor t, Foldable t) => Traversable t
jaspervdj 2017-02-28 07:36:41
registration for the yearly zurich haskell hackathon has opened :-)
kubunto 2017-02-28 07:41:57
is it possible to execute a string as a line of haskell?
sm 2017-02-28 07:43:10
ghc -e 'putStrLn "hello"'
EvanR 2017-02-28 07:43:15
theres mueval
kubunto 2017-02-28 07:44:23
mueval?
EvanR 2017-02-28 07:44:35
> putStrLn "hello"
lambdabot 2017-02-28 07:44:38
EvanR 2017-02-28 07:44:44
> let x = x in x
lambdabot 2017-02-28 07:44:50
mueval-core: Time limit exceeded