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

Commit

Permalink
Add ICE reproduction for issue rust-lang/rust#79768.
Browse files Browse the repository at this point in the history
  • Loading branch information
rustbot committed Dec 7, 2020
1 parent 39cb7eb commit 3e56863
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions ices/79768.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#![feature(generic_associated_types)]

trait Monad /* : Applicative (for pure/return, doesn't matter for this example) */ {
// Self is like the "f a" in haskell

/// extract the "a" from "f a"
type Unplug;

/// exchange the "a" in "f a" in the type of Self with B
type Plug<B>: Monad;

fn bind<B, F>(self, f: F) -> Self::Plug<B>
where
F: Fn(Self::Unplug) -> Self::Plug<B>;
}

impl<A> Monad for Option<A> {
type Unplug = A;
type Plug<B> = Option<B>;
fn bind<B, F>(self, f: F) -> Option<B>
where
F: Fn(A) -> Option<B>,
{
self.and_then(f)
}
}

// This function causes the compiler error, specifically, when i added the Plug = P constraint.
fn stringify<T, M1, P>(m: M1) -> M1::Plug<P>
where
T: core::fmt::Display,
M1: Monad<Unplug = T, Plug = P>,
{
m.bind(|x| format!("{}", x))
}

fn main() {
let x = Some(1).bind(|x| Some(x * 2));
println!("{:?}", x);
}

0 comments on commit 3e56863

Please sign in to comment.