Skip to content
This repository was archived by the owner on May 23, 2024. It is now read-only.

Commit 856eea2

Browse files
authored
Merge pull request #557 from rustbot/triagebot-ice-79768
ICE - rust-lang/rust#79768
2 parents 39cb7eb + 3e56863 commit 856eea2

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

ices/79768.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#![feature(generic_associated_types)]
2+
3+
trait Monad /* : Applicative (for pure/return, doesn't matter for this example) */ {
4+
// Self is like the "f a" in haskell
5+
6+
/// extract the "a" from "f a"
7+
type Unplug;
8+
9+
/// exchange the "a" in "f a" in the type of Self with B
10+
type Plug<B>: Monad;
11+
12+
fn bind<B, F>(self, f: F) -> Self::Plug<B>
13+
where
14+
F: Fn(Self::Unplug) -> Self::Plug<B>;
15+
}
16+
17+
impl<A> Monad for Option<A> {
18+
type Unplug = A;
19+
type Plug<B> = Option<B>;
20+
fn bind<B, F>(self, f: F) -> Option<B>
21+
where
22+
F: Fn(A) -> Option<B>,
23+
{
24+
self.and_then(f)
25+
}
26+
}
27+
28+
// This function causes the compiler error, specifically, when i added the Plug = P constraint.
29+
fn stringify<T, M1, P>(m: M1) -> M1::Plug<P>
30+
where
31+
T: core::fmt::Display,
32+
M1: Monad<Unplug = T, Plug = P>,
33+
{
34+
m.bind(|x| format!("{}", x))
35+
}
36+
37+
fn main() {
38+
let x = Some(1).bind(|x| Some(x * 2));
39+
println!("{:?}", x);
40+
}

0 commit comments

Comments
 (0)