Skip to main content

oxilean_codegen/haskell_backend/
haskellinstance_traits.rs

1//! # HaskellInstance - Trait Implementations
2//!
3//! This module contains trait implementations for `HaskellInstance`.
4//!
5//! ## Implemented Traits
6//!
7//! - `Display`
8//!
9//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
10
11use crate::lcnf::*;
12
13use super::functions::*;
14use super::types::HaskellInstance;
15use std::fmt;
16
17impl fmt::Display for HaskellInstance {
18    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19        if !self.context.is_empty() {
20            write!(f, "instance (")?;
21            for (i, c) in self.context.iter().enumerate() {
22                if i > 0 {
23                    write!(f, ", ")?;
24                }
25                write!(f, "{}", c)?;
26            }
27            write!(f, ") => ")?;
28        } else {
29            write!(f, "instance ")?;
30        }
31        write!(
32            f,
33            "{} {} where",
34            self.class,
35            paren_type(&self.instance_type)
36        )?;
37        for func in &self.where_clause {
38            let func_str = func.to_string();
39            for line in func_str.lines() {
40                write!(f, "\n  {}", line)?;
41            }
42        }
43        Ok(())
44    }
45}